title: php file upload, how to restrict file upload type
body: <p>I have the following code to check if (resume and reference letter uploaded match desired type (pdf OR doc OR docx) and size (less than 400 kb)</p>
  
  <pre><code>//check file extension and size
           $resume= ($_FILES['resume']['name']); 
           $reference= ($_FILES['reference']['name']); 
           $ext = strrchr($resume, ".");
           $ext1 = strrchr($reference, ".");
          if (!(($_FILES["resume"]["type"] == "application/doc")
          || ($_FILES["resume"]["type"] == "application/docx")
          || ($_FILES["resume"]["type"] == "application/pdf" ))
           &amp;&amp; (($_FILES["reference"]["type"] == "application/doc")
          || ($_FILES["reference"]["type"] == "application/docx")
          || ($_FILES["reference"]["type"] == "application/pdf"))
          &amp;&amp; (($ext == ".pdf") || ($ext == ".doc") || ($ext == ".docx"))
          &amp;&amp; (($ext1 == ".pdf") || ($ext1 == ".doc") || ($ext1 == ".docx"))
          &amp;&amp;  ($_FILES["resume"]["size"] &lt; 400000) //accept upto 500 kb
          &amp;&amp;  ($_FILES["reference"]["size"] &lt; 400000)) {  
  
  stop user } else { allow files to upload }
  </code></pre>
  
  <p>This is not working as desired, allows even txt files through + the size limit is not being checked, what is wrong with it?</p>
  
  <p>Thanks,</p>