title: What is the difference between $_FILES["file"]["type"] and end(explode(".", $_FILES["file"]["name"]))
body: <p>I use <code>var_dump(@$_FILES['file']['type'])</code> to test file type I uploaded</p>
  
  <p>First, I uploaded an <code>exe file</code> called "<code>uninstall.exe</code>", and it returned </p>
  
  <pre><code>"string 'application/octet-stream' (length=24)"
  </code></pre>
  
  <p>Then, I renamed this file to <code>uninstall.png</code>, it returned </p>
  
  <pre><code>string 'image/png' (length=9)
  </code></pre>
  
  <p>My conclusion is: <strong>$_FILES['file']['type'] only check file extension, not the original file type.</strong></p>
  
  <p>The following code is from <a href="http://www.w3schools.com/php/php_file_upload.asp" rel="noreferrer">w3cschool</a>:</p>
  
  <pre><code>$allowedExts = array("gif", "jpeg", "jpg", "png");
  $extension = end(explode(".", $_FILES["file"]["name"]));
  if ((($_FILES["file"]["type"] == "image/gif")
  || ($_FILES["file"]["type"] == "image/jpeg")
  || ($_FILES["file"]["type"] == "image/jpg")
  || ($_FILES["file"]["type"] == "image/png"))
  &amp;&amp; ($_FILES["file"]["size"] &lt; 20000)
  &amp;&amp; in_array($extension, $allowedExts))
  </code></pre>
  
  <p>I think <code>$_FILES["file"]["type"]</code> in above codes is unnecessary, we can just check file extension using <code>explode()</code> and <code>in_array</code></p>
  
  <p>I'm just a php beginner, can someone confirm my idea? Thanks!</p>