Laravel Input :: hasFile ('image') returns false even if the file is uploaded

I have a form field for uploading an image that I open with "files" => true, for example:

{{ Form::label('image', 'Image') }} {{ Form::file('image') }} 

And in my controller, I want to check if the file has been downloaded and do something with it:

 if (Input::hasFile('image')){ $in_path = 'img/'; $in_extension = Input::file('image')->getClientOriginalExtension(); $filename = Input::get('name').".".$in_extension; Input::file('image')->move($in_path, $filename); $user->image = $filename; } 

But Input :: hasFile always returns false, and I don't know why.
Anyone have an idea?

EDIT:

 Input::file('image'); 

leads to:

 Symfony\Component\HttpFoundation\File\UploadedFile Object ( [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => test.JPG [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream [size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0 [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1 [pathName:SplFileInfo:private] => [fileName:SplFileInfo:private] => ) 

I tested a different picture for another user and it works great. I do not understand why this works for some users, but not for some others.
Are there any photos that are not accepted?

+7
php file-upload laravel
source share
3 answers

I decided what happened. The code is ok, but the problem was that some of the photos were just big.



EDIT:

As Do not Panic pointed out, editing upload_max_filesize can solve the problem.

+2
source share

How do you open a form? If you want your form to accept files, you need to open them like this:

 echo Form::open(array('url' => 'foo/bar', 'files' => true)) 

Opening a form in Laravel Docs

+8
source share

I had the same problem, I checked my code and noticed that I didn’t have the enctype = "multipart / form-data" header in the form, hope this great neglect helps someone

+2
source share

All Articles