PHP upload fail for some PDF files (empty MIME type)
I have a application that allows upload of PDF files and compressed files (zip, rar, tar, etc...). I'm using this list of MIME types as reference to check the type of the files.
Here is PHP snippet for upload:
//this function is called by AJAX
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$check= finfo_file($finfo,$file["tmp_name"]);
finfo_close($finfo);
if ($check != 'application/pdf' && $check != 'application/x-rar-compressed' && $check != 'application/x-rar'
&& $check != 'application/zip' && $check != 'application/x-compressed' && $check != 'application/x-zip-compressed' && $check != 'multipart/x-zip'
&& $check != 'application/octet-stream' && $check != 'application/gzip' && $check != 'application/tar'
&& $check != 'application/tar+gzip') {
echo json_encode(array('msg'=>'error. Try PDF or compressed file (zip, rar)'));exit();
}
if ($file['size'] > 10485760) { //10 MB
echo json_encode(array('msg'=>'error. Max size is 10MB'));exit();
}
$upload = new Upload($file);//Helper class to upload files
//the file is saved
All working fine in my local environment and also in the server when I make the tests, but my client is using a PDF file that is throwing the "error. Try PDF or compressed file (zip, rar)".
I got the same file that he's using(by email) and when I test on my local machine all works fine. In the debug, the $check
var has the value application/pdf
.
Looking for any solution I found this question in SO and now I thinking. Should I include the application/vnd.pdf
, application/x-pdf
or even text/pdf
in the first if
block? It could compromise my application?
I'm using Firefox, but also tested in Chrome and Opera. He noted this bug in IE11, but also in Chrome. Is it possible that his computer or the browser is changing the MIME type?
Note: The problematic file has a name like "file.PDF"(PDF is Caps Lock), but I don't think it is causing the problem. As I said, the same file works in my tests.
UPDATE
Following the @fusion3k's suggestion in the comments, I printed the $check
var with the error message. Now when I try to upload a image for example I get:
Try PDF or compressed file (zip, rar). image/jpeg
The problem now is that the problematic files (it's more than one now) are printing a empty string after error message and I don't know what to do, once the MIME type is, apparently, empty.
According to the user, the PDF is generated by a old scanner and I think that could be the problem, but the strange thing is the same file (when sent to me by e-mail) working fine.
链接地址: http://www.djcxy.com/p/8194.html上一篇: 请求和EchoSign