title: Mime Type vs Extension Check, which method is better to check file type?
body: <p>I'm creating a script to upload image file. There are two ways to verify if the file is an image.</p>
  
  <p>First one is by checking the extension:</p>
  
  <pre><code>$extension = strtolower(substr($filename, strrpos($filename, '.') + 1, strlen($filename) - strrpos($filename, '.')));
  if ($extension == "jpg") // UPLOAD
  </code></pre>
  
  <p>Another one is by checking the mime type:</p>
  
  <pre><code>$imageinfo = getimagesize($filename);
  if ($imageinfo['mime'] == "image/jpeg") // UPLOAD
  </code></pre>
  
  <p>Which one is the better method to verify if the file is an image?</p>