title: How to check file types of uploaded files in PHP?
body: <p>On the PHP website, the only real checking they suggest is using <code>is_uploaded_file()</code> or <code>move_uploaded_file()</code>, <a href="http://ca.php.net/manual/en/features.file-upload.php" rel="noreferrer">here</a>. Of course you usually don't want user's uploading any type of file, for a variety of reasons.</p>
  
  <p>Because of this, I have often used some "strict" mime type checking. Of course this is very flawed because often mime types are wrong and users can't upload their file. It is also very easy to fake and/or change. And along with all of that, each browser and OS deals with them differently.</p>
  
  <p>Another method is to check the extension, which of course is even easier to change than mime type.</p>
  
  <p>If you only want images, using something like <code>getimagesize()</code> will work.</p>
  
  <p>What about other types of files? PDFs, Word documents or Excel files? Or even text only files?</p>
  
  <p><strong>Edit:</strong> If you don't have <a href="http://php.net/manual/en/function.mime-content-type.php" rel="noreferrer">mime_content_type</a> or <a href="http://php.net/manual/en/function.finfo-file.php" rel="noreferrer">Fileinfo</a> and system("file -bi $uploadedfile") gives you the wrong file type, what other options are there?</p>