Framework: Bug with non image file upload

Created on 4 Apr 2017  路  7Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.17
  • PHP Version: 7.1.3
  • Database Driver & Version: pdo_mysql, mysql 5.7.17

Description:

When uploaded files are of the type image, they get uploaded properly. Non-image (atleast PDF in my case) doesn't work.

Steps To Reproduce:

  1. Make an upload form (with proper setup i.e. enctype and input component with multiple files)
  2. Put validation in place ('field.*' => 'required|image')
  3. Upload an image file, it should work
  4. Change validation appropriately (required|mimesType:application/pdf)
  5. With the same code upload a non-image file and you should get an error with the upload (validation.uploaded is triggered) in the session error

Some more details

Doing a dump on $request to investigate gave some more details, which may be helpful. When it errors, it has the following request dump:

0 => UploadedFile {#111
      -test: false
      -originalName: "filename.pdf"
      -mimeType: "application/octet-stream"
      -size: 0
      -error: 1
      #hashName: null
      path: ""
      filename: ""
      basename: ""
      pathname: ""
      extension: ""
      realPath: "CODEHOME/public"
      aTime: 1970-01-01 01:00:00
      mTime: 1970-01-01 01:00:00
      cTime: 1970-01-01 01:00:00
      inode: false
      size: false
      perms: 00
      owner: false
      group: false
      type: false
      writable: false
      readable: false
      executable: false
      file: false
      dir: false
      link: false
    }

but when it works, i.e. with the image file, the dump is more sensible

    0 => UploadedFile {#111
      -test: false
      -originalName: "12040002.jpg"
      -mimeType: "image/jpeg"
      -size: 807682
      -error: 0
      #hashName: null
      path: "/tmp"
      filename: "phpBTeakk"
      basename: "phpBTeakk"
      pathname: "/tmp/phpBTeakk"
      extension: ""
      realPath: "/tmp/phpBTeakk"
      aTime: 2017-04-04 22:56:50
      mTime: 2017-04-04 22:56:50
      cTime: 2017-04-04 22:56:50
      inode: 37365
      size: 807682
      perms: 0100600
      owner: 33
      group: 33
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
    }

Note that while I have mentioned the validation details above, the dump is taken prior to the validator method in the controller, so it probably shouldn't have any impact on the issue.

As is visible, it's probably trying to upload the file to the project root, instead of '/tmp' when doing the non-image upload and that's why it's likely failing.

(I have just renamed the folder name in the dump to CODEHOME)

All 7 comments

validation.uploaded means the file failed to upload, there are many reasons for that that you need to explore yourself.

You're correct, and that was my first thought as well.

As I have explained in the issue above, I have used the same upload form while changing only the type of file I uploaded. Also, the files being uploaded were from the same local folder.

The realPath changing makes me inclined to think that this could be a bug.

I will continue to check this further and report back if anything changes.

what is the size of the pdf you are uploading? Are you sure it is not greater than your file max size?

Okay, there is an update.

Good: Other files were uploading

Bad: One particular PDF is not uploading. Renaming it doesn't help either. It's not a secure file but of PDF-1.5 format. The ones I can upload are PDF-1.4

@laurencei wow, this is embarrassing. The one thing I should've checked, I never event thought to do. That's indeed the case.

Closing the bug

what is the size of the pdf you are uploading? Are you sure it is not greater than your file max size?

Thanks , it works for me .

same problem with me with any file what is the reason??

Was this page helpful?
0 / 5 - 0 ratings