jabba's avatar

PDF upload problem

Hello!

I have an application based on Laravel 4.2.17 with file upload funcionality. Everythink works fine except uploading of some PDF files.

During last few days my colleague uploaded several hundreds of PDF files, but several of them can't be uploaded. When we tried to open it, they seems normal like any other PDF file.

dd(Input::('file')) says this:

Symfony\Component\HttpFoundation\File\UploadedFile Object
(
    [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 
    [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => ponuda524.pdf
    [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] => 
)

We suspect that the problem is related to detection of mimetypes. PDF files are made from Word 2010 docx files, converted with Nitro Professional 7 and "Save as.." option built in Word. Both failed.

0 likes
11 replies
skashizadeh's avatar

use dd(Input::file('input_name')->getMimeType() ) to see those pdf's mimetype :) , and then support them too ;)

'application/octet-stream'
jabba's avatar

Thanks for tip.

I think this is a PHP fileinfo extension problem. When i try to upload PDF 1.5 it's failing, but when i try to upload PDF/A-1 everything works fine.

skashizadeh's avatar

maybe your file currepted by non-sense app before , and for your prev reply i told you to use

dd(Input::file('input_name')->getMimeType() )

not using php's mime_content_type()

skashizadeh's avatar

pdf mimetype is not something that you could rely on. i think you must check if mimetype is not recognized by browser ( 'application/octet-stream' ) then extension is right and file has only one extension :

$extension = Input::file('input_name')->getClientOriginalExtension();

hope works for you.

jabba's avatar
Symfony \ Component \ HttpFoundation \ File \ Exception \ FileNotFoundException
The file "" does not exist 
skashizadeh's avatar

you changed 'input_name' with your input's name , right? becouse seems you are trying to access something that is not exist.

jabba's avatar

Ofcourse I did. PHP just cant read complete file stream.

I'm going to investigate this using plain PHP.

Twkrks's avatar

Jabba, did you ever find out how to fix this? I am running into the exact same problem. Thanks in advance!

Twkrks's avatar

Oh I fixed this: it turned out that the PDF had a bigger file size than allowed by upload_max_filesize in php.ini.

Please or to participate in this conversation.