title: PHP upload file fails with 0 length array.
body: <p>I am trying to upload a file using php.  The script works sometimes flawlessly, but other times it does not. When it doesn't work, the $_FILES array is completetly empty (print_r yields Array()). I can't error check because $_FILES["file"]["error"] is empty.  The behaviour is consistent through IE, Chrome, and Firefox.  The file seems to be uploading as the progress bar indicates.</p>
  
  <p>The scipt as it stands returns Invalid file type again because $_FILES is empty.  If I remove the file type check, move_uploaded_file returns false and the script returns my custom "file may have failed" message.  The only errors error_reporting returns are index errors whenever I try and access $_FILES - again because it is empty.</p>
  
  <p>I have seen other questions with file upload issues, but I haven't come across anyone with this specific problem.  I can't think it is a permissions issue, because, as I said the script does work sometimes.  Although I am testing for multiple file types, I have only tried to upload mp3 files.    </p>
  
  <pre><code>ini_set('display_errors',1);
  error_reporting(E_ALL);
  
  print_r($_FILES);
  
  if  (($_FILES["file"]["type"] == "image/gif")
      || ($_FILES["file"]["type"] == "image/jpeg")
      || ($_FILES["file"]["type"] == "application/pdf")
      || ($_FILES["file"]["type"] == "audio/mpeg")
      || ($_FILES["file"]["type"] == "audio/x-mp3")
      || ($_FILES["file"]["type"] == "image/pjpeg"))
  {
  
  
      if ($_FILES["file"]["error"] &gt; 0)
      {
          echo "\nReturn Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
      }
      else
      {
          echo "\nUpload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
          echo "\nType: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
          echo "\nSize: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
          echo "\nTemp file: " . $_FILES["file"]["tmp_name"] . "&lt;br /&gt;";
          $fname = basename($_FILES["file"]["name"]);
          $put_file = $_POST["put_dir"] . "/" . $fname;
          echo "\nDestination File: " . $put_file . "&lt;br /&gt;";
  
          if(move_uploaded_file($_FILES["file"]["tmp_name"], $put_file))
          {
              echo "The file " .  $fname . " has been uploaded";              
  
          }
          else
          {
              echo "The file " .  basename( $_FILES['file']['name']) . " may have failed";
          }
      }
  }
  else
  {
      echo "Invalid file type: " . $_FILES["file"]["type"];
  }
  </code></pre>