title: PHP: How to properly check MIME type of a file?
body: <p>I have an input where you can upload images, the only allowed images types are: </p>
  
  <pre><code>png, jpg, jpeg
  </code></pre>
  
  <p>before the image is inserted to the database it checks if the pictures are png,jpg,jpeg. But now for security reasons I need to check the mime type before or after the first check.</p>
  
  <p>How do I do this? This is my code:</p>
  
  <pre><code>&lt;?php
  
  $iAmountOfFiles = count($_FILES['Filename']['name']);
  
  while($iAmountOfFiles &gt;= 1) {
  
      $iAmountOfFiles--;
  
      $aFileProperties = pathinfo($_FILES['Filename']['name'][$iAmountOfFiles]);
      if(!in_array(strtolower($aFileProperties["extension"]), $aExtensionWhitelist)) {
          echo "Bestands type niet toegestaan";
          // exit;
          continue;
      }
  
      $sTarget = ROOT.BACKEND."/pages/bezienswaardigheden-toevoegen/uploads/";
      $sUniqueFileNameHash = hash('adler32', time().rand());
      $Filename = basename($sUniqueFileNameHash."-".$_FILES['Filename']['name'][$iAmountOfFiles]);
      $Filename = basename($aFileProperties["filename"]."-".$sUniqueFileNameHash.".".strtolower($aFileProperties["extension"]));
  
      // Writes the Filename to the server
      if(move_uploaded_file($_FILES['Filename']['tmp_name'][$iAmountOfFiles], $sTarget.$Filename)) {
  
      // here needs to come the mime check
  </code></pre>