title: PHP upload code problem with permitted MIME file types
body: <p>I have a file (image) upload script in PHP that I use to upload and resize images... It uses a simple MIME type and size validation so only jpg images are allowed and 1MB max file size.</p>
  
  <p>I recently discovered a problem. When I try tu upload a .avi file using the script, the script processes the file like its the correct MIME type and size and then just do nothing, just takes me back to the upload form without any error message. (Instead of showing a "file too big" message).</p>
  
  <p>I mean, if I try to upload a .gif or .txt or something else I get an error, as expected.
  If I try to upload any file bigger than 1MB I get an error, as expected.
  Only when I try to upload a .avi file with more than 1MB I dont get any kind of error.....
  Well, here the first par of the code:</p>
  
  <pre><code>// define a constant for the maximum upload size
  define ('MAX_FILE_SIZE', 1024000);
  
  if (array_key_exists('upload', $_POST)) {
  // define constant for upload folder
  define('UPLOAD_DIR', 'C:/Wamp/www/Version-1.4/posters_uploaded/');
  
  // replace any spaces in original filename with underscores. At the same time, assign to a simpler variable
  $file = str_replace(' ', '_', $_FILES['image']['name']);
  
  // convert the maximum size to KB
  $max = number_format(MAX_FILE_SIZE/1024, 1).'kb';
  // create an array of permitted MIME types
  $permitted = array('image/jpeg','image/pjpeg');
  // begin by assuming the file is unacceptable
  $sizeOK = false;
  $typeOK = false;
  
  // check that file is within the permitted size
  if ($_FILES['image']['size'] &gt; 0 &amp;&amp; $_FILES['image']['size'] &lt;= MAX_FILE_SIZE) {
      $sizeOK = true;
  }
  // check that file is of a permitted MIME type
  foreach ($permitted as $type) {
      if ($type == $_FILES['image']['type']) {
          $typeOK = true;
      break;
      }
  }
  
  if ($sizeOK &amp;&amp; $typeOK) {
      switch($_FILES['image']['error']) {
          case 0: // ...................
  </code></pre>
  
  <p>I'm just modifying a build PHP code so Im no expert...
  Any suggestions??
  Thanks.</p>