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.

Nathan
  • 2,699
  • 5
  • 30
  • 44
  • What is the problem that you are facing...?? – Vagabond Feb 18 '15 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. – Nathan Feb 18 '15 at 17:37
  • We are having the same problem. $_FILES shows an array with the file but Input::file('file') is showing nothing. – William H Mar 10 '15 at 21:23

1 Answers1

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
fire
  • 21,383
  • 17
  • 79
  • 114
  • 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. – Nathan Feb 18 '15 at 17:32
  • Try using the Log class to log the object and see what happens. Are you actually clicking the button or using AJAX? – fire Feb 18 '15 at 17:37