title: Print/debug cause of upload error in PHP
body: <p>I'm a PHP newbie and have written a script to process form uploads. It works for small files(less than 1Mb). However when I try to upload an ~4Mb pdf file it returns an error message. What am I doing wrong?</p>
  
  <p>PS: I ran php_info, got the value of "upload_tmp_dir" and set it to a directory owned by the apache process(www-data)</p>
  
  <p>My client-side code is</p>
  
  <pre><code>&lt;form action="upper.php" method="post" enctype="multipart/form-data"&gt; 
      &lt;input type="file" name="myFile"&gt;&lt;br&gt;
      &lt;input type="submit" value="Upload"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Upper.php contains</p>
  
  <pre><code>define("UPLOAD_DIR", "/var/www/html/upload/");
  
  if (!empty($_FILES["myFile"])) {
      $myFile = $_FILES["myFile"];
  
      if ($myFile["error"] !== UPLOAD_ERR_OK) {
          echo "Error is " . $myFile["error"];
          //echo "&lt;p&gt;An error occurred.&lt;/p&gt;";
          exit;
      }    
  
      $name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]);
  
      // don't overwrite an existing file
      $i = 0;
      $parts = pathinfo($name);
      while (file_exists(UPLOAD_DIR . $name)) {
          $i++;
          $name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
      }
  
      // preserve file from temporary directory
      $success = move_uploaded_file($myFile["tmp_name"], UPLOAD_DIR . $name);
      if (!$success) {
          echo "&lt;p&gt;Unable to save file.&lt;/p&gt;";
          exit;
      }
  
      // set proper permissions on the new file
      chmod(UPLOAD_DIR . $name, 0644);
  }
  </code></pre>