PHP upload fail for some PDF files (empty MIME type)
<p>I have a application that allows upload of PDF files and compressed files (zip, rar, tar, etc...). I'm using this list of <a href="http://www.sitepoint.com/web-foundations/mime-types-complete-list/" rel="nofollow noreferrer">MIME types</a> as reference to check the type of the files.</p>

<p>Here is PHP snippet for upload:</p>

<pre><code>//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' &amp;&amp; $check != 'application/x-rar-compressed' &amp;&amp; $check != 'application/x-rar'
    &amp;&amp; $check != 'application/zip' &amp;&amp; $check != 'application/x-compressed' &amp;&amp; $check != 'application/x-zip-compressed' &amp;&amp; $check != 'multipart/x-zip'
    &amp;&amp; $check != 'application/octet-stream' &amp;&amp; $check != 'application/gzip' &amp;&amp; $check != 'application/tar'
    &amp;&amp; $check != 'application/tar+gzip') {
        echo json_encode(array('msg'=&gt;'error. Try PDF or compressed file (zip, rar)'));exit();
}
if ($file['size'] &gt; 10485760) { //10 MB
    echo json_encode(array('msg'=&gt;'error. Max size is 10MB'));exit();
}
$upload = new Upload($file);//Helper class to upload files
//the file is saved
</code></pre>

<p>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)".</p>

<p>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 <code>$check</code> var has the value <code>application/pdf</code>.</p>

<p>Looking for any solution I found <a href="https://stackoverflow.com/questions/312230/proper-mime-media-type-for-pdf-files">this question</a> in SO and now I thinking. Should I include the <code>application/vnd.pdf</code>, <code>application/x-pdf</code> or even <code>text/pdf</code> in the first <code>if</code> block? It could compromise my application?</p>

<p>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?</p>

<p>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.</p>

<p><strong>UPDATE</strong></p>

<p>Following the @fusion3k's suggestion in the comments, I printed the <code>$check</code> var with the error message. Now when I try to upload a image for example I get:</p>

<blockquote>
  <p>Try PDF or compressed file (zip, rar). image/jpeg</p>
</blockquote>

<p>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.</p>

<p>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.</p>