laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.39k stars 10.98k forks source link

Problem uploading files using Input::file() bug? #485

Closed ghost closed 11 years ago

ghost commented 11 years ago

I'm trying to upload a file and the Input::file keeps returning null.

Example form

$file = Input::file() returns null. $file = Input::file('image') returns null. $file = Input::all() returns null.

brunogaspar commented 11 years ago

Do you have the correct enctype on your form?

Please don't create issues if you are not sure if it is a bug, post on forums instead.

ghost commented 11 years ago

Yes I have enctype="multipart/form-data" set on the form.

brunogaspar commented 11 years ago

What type of file are you trying to upload?

brunogaspar commented 11 years ago

From my tests

My view

<form method="post" enctype="multipart/form-data">

<p><input type="file" name="test"></p>

<p><input type="submit"></p>

</form>

My POST Route

var_dump(Input::file());
var_dump(Input::file('test'));

Returns

array (size=1)
  'test' => 
    object(Symfony\Component\HttpFoundation\File\UploadedFile)[9]
      private 'test' => boolean false
      private 'originalName' => string '135079122234.gif' (length=16)
      private 'mimeType' => string 'application/octet-stream' (length=24)
      private 'size' => int 0
      private 'error' => int 1

object(Symfony\Component\HttpFoundation\File\UploadedFile)[9]
  private 'test' => boolean false
  private 'originalName' => string '135079122234.gif' (length=16)
  private 'mimeType' => string 'application/octet-stream' (length=24)
  private 'size' => int 0
  private 'error' => int 1

I tested with JPG, PNG, GIF, TXT and PDF, all showed up correctly for me

ghost commented 11 years ago

I'm trying to upload a JPG. I tried mutiple file types everything is returning null.

Form:

    form action="image/add" method="post" enctype="multipart/form-data"
    input type="file" name="photo"
    input type="submit" value="Upload" 

( I stripped the tags open/close tags cause it kept showing up blank )

Route:

var_dump(Input::file());
var_dump(Input::file('photo'));

Result:

array  empty
null
JoostK commented 11 years ago

Just try the native PHP superglobal $_FILES to see if this is a Laravel issue, as I don't think so.

ghost commented 11 years ago

$_FILES is returning null also so cant be Laravel. My mistake for thinking this was related to Laravel!

vanderlin commented 10 years ago

I am having this same issue very strange.

Input::get('photo'); // returns [] $_FILES['photo'] // I get the object

Not sure why this is happening, I dug down and see that Symfony2 is the Request and looks like it should be set. Any thoughts?

Cederman commented 10 years ago

I have the same issue as vanderlin

manfredjb commented 10 years ago

Please, considere check "upload_max_filesize" php php enviroment

stayallive commented 10 years ago

@vanderlin, @Cederman You should use Input::file('photo') to get the uploaded file object.

If you use Input::get(...) on a file upload you should get the filename I believe...

=> Just for google/search... know this is history :)

kaankilic commented 9 years ago

I have same problem.I read all comments about the bug.Also, I considered to upload_max_size and post_max_size configurations.still it's not working again.

FlashPapa commented 9 years ago

I have same problem !

$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);

Don't work, it give me a file with this inside : /private/var/tmp/phpNz8cZJ

And I have the same probleme with this code -> move_uploaded_file(Input::file("file"), "uploads/image".$id.".jpg"); The file is broken...

But when i acces with no profixy, it's working ! I do my test like this -> Image of Yaktocat

prasadmunna commented 8 years ago

i got an error while i am using summernote and post data into my controller

[files] => Symfony\Component\HttpFoundation\File\UploadedFile Object ( [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 38h_900.jpg [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg [size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 170689 [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0 [pathName:SplFileInfo:private] => C:\xampp\tmp\php242E.tmp [fileName:SplFileInfo:private] => php242E.tmp ) )

papalardo commented 4 years ago

Please, considere check "upload_max_filesize" php php enviroment

This works with me. Remember restart php-fpm

$ php -i | grep "Loaded Configuration File"
$ code /usr/local/etc/php/7.4/php.ini      
## Change line upload_max_filesize
$ php -i | grep "upload_max_filesize" ## Verify
brew services restart php@7.4