title: the most reliable way to check upload file is an image
body: <p>I want to validate my upload files is it an images or not. after searching i found two way that i think is a good way to do it. the first code is:</p>
  
  <pre><code>$whitelist_type = array('image/jpeg', 'image/png','image/gif');
  $fileinfo = finfo_open(FILEINFO_MIME_TYPE);
  
  if (!in_array(finfo_file($fileinfo, $file['tmp_name']), $whitelist_type)) {
  $error[]  = "Uploaded file is not a valid image";
  }
  </code></pre>
  
  <p>and the second code:</p>
  
  <pre><code>if (!getimagesize($_FILES['photo']['tmp_name'])) {
  $error[]  = "Uploaded file is not a valid image";
  }
  </code></pre>
  
  <p>which code is more reliable to check that it's an images and why? or is it any better way than this? thanks.</p>