2

To keep it simple, I have this in my view:

{{ Form::open(['route' => 'files', 'method' => 'POST', 'files' => 'true']) }}
{{ Form::file('file') }}
{{ Form::submit(); }}
{{ Form::close() }}

And in my controller:

return Response::json([$_FILES, print_r(Input::file('file'),1)]);

This is the response I get when I submit:

[
    {
        "file": {
            "name": "sample.jpg",
            "type": "image/jpeg",
            "tmp_name": "/tmp/phpItZT7K",
            "error": 0,
            "size": 17645
        }
    },
    {}
]

The only real solutions I've come across while searching is the enctype, which I have on my form via the 'files' attribute in Form::open. At this point, I have no idea what's going on. It's not application-breaking, but it's still annoying. If anyone could shed some light on this, I'd be very happy.

3
  • What is the problem that you are facing...?? Commented Feb 18, 2015 at 17:26
  • Input::file() was returning no data. No UploadedFile object or anything. It has since then magically started working again between refreshes without my changing any code that was relevant, or so I believe. Commented Feb 18, 2015 at 17:37
  • We are having the same problem. $_FILES shows an array with the file but Input::file('file') is showing nothing. Commented Mar 10, 2015 at 21:23

1 Answer 1

2

You haven't clarified what the actual problem is but I am guessing it's the Input::file() not coming through the JSON. That's because Input::file() returns a symfony object which can't be encoded so you would have to create your own array.

$file = Input::file('file');
$output = ['name' => $file->getClientOriginalName(), 'size' => $file->getClientSize()]; // etc
Sign up to request clarification or add additional context in comments.

2 Comments

I'm was using print_r(Input::file('file'),1) to print in the JSON output, and it was always blank. I just forgot to include that in the post.
Try using the Log class to log the object and see what happens. Are you actually clicking the button or using AJAX?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.