Check picture file type and size before file upload in php
<p>I have the following code:</p>

<pre><code>$filecheck = basename($_FILES['imagefile']['name']);
  $ext = substr($filecheck, strrpos($filecheck, '.') + 1);
  if (($ext == "jpg" || $ext == "gif" || $ext == "png") &amp;&amp; ($_FILES["imagefile"]["type"] == "image/jpeg" || $_FILES["imagefile"]["type"] == "image/gif" || $_FILES["imagefile"]["type"] == "image/png") &amp;&amp; 
    ($_FILES["imagefile"]["size"] &lt; 2120000)){
} else {
echo "F2";
die();
}
</code></pre>

<p>What i need to do is check if the uploaded file is a jpg/gif/png and that its less than 2 megs in size.</p>

<p>If its larger than 2 megs, or not the right file type, i need to return/echo F2 (error code for api).</p>

<p>When i use the code above to process a 70k jpg file, it returns F2.</p>

<p><strong>SUBNOTE</strong>
the picture im uploading has an extension of .JPG. Could case be a factor? If so, how do i accommodate for that?</p>
