Reputation: 4541
I have a form that has a field to upload multiple files. So far so good. So when I select a few files and hit the submit button, the $request->file()
is always empty no matter what. The name of my field is images_json
.
I suspected the route being PATCH
or PUT
could cause this (considering I'm uploading images on create and update), I made a separate POST route to handle the uploading with its own controller action and had a 3rd party jQuery plugin handle the upload (blueimp jQuery File Upload plugin), and guess... I'm receiving an empty response yet again!
And yes I have 'files' => true
in my form tag and it spits the enctype="multipart/form-data"
attribute very nicely.
This is what I have in my view currently (normal file upload that relies on the submit button of the form):
<div class="form-group form-md-line-input">
{!! Form::label('images_json', 'Bilder hochladen', ['class' => 'col-md-2 control-label']) !!}
<div class="col-md-10">
<div class="fileinput fileinput-new" data-provides="fileinput">
<span class="btn green-seagreen btn-file">
<i class="glyphicon glyphicon-plus"></i>
<span class="fileinput-new">Bilder auswählen...</span>
<span class="fileinput-exists">Mehr auswählen</span>
{!! Form::file('images_json[]', ['multiple']) !!}
</span>
<span class="fileinput-preview" style="max-height: 32px;"></span>
<a href="javascript:;" class="close fileinput-exists" data-dismiss="fileinput"></a>
</div>
</div>
</div>
And this is the action:
public function update(CreateEntryRequest $request, $id)
{
return $request->file('images_json');
}
And this would be a response:
[{},{},{}]
(Yes, I selected three pictures)
No matter what, it always comes back as blank. This is now something I am unable to figure out.
Upvotes: 2
Views: 3722
Reputation: 321
try put this in the top of your controller file
use Illuminate\Http\UploadedFile;
Upvotes: 0
Reputation: 1360
I think you sent data via ajax, so you can try to get file from $_FILES
.
I have the same problem with fineuploader, and solve it when obtained data from $_FILES
instead $request->file()
Upvotes: 3