title: Unable to upload high dimension images in php
body: <p>I have developed a small image upload system with lot of customization like (renaming, thumbnail generating, validation).<br>
  All features are working perfectly except Images with high dimension (2000x2000 upwards).<br>
  I can't recognize the issue.</p>
  
  <p>Following is my <strong>upload.php</strong></p>
  
  <pre><code>if (isset($_POST['upload'])) {
      $i_image = $_POST['image'];
      $fund_id = $_POST['fid'];
      $image = $_POST['image'];
      // check the existence 
      $ex = mysql_query("SELECT pid, fid, image FROM imgs WHERE fid = '$fund_id' AND image = '$image'");
      if(mysql_num_rows($ex)&gt; 0){
          echo 'Image already exists!!';
      }else{
          $newpath = $_POST['path'];
          $cfn = $_POST['cfn'];
          if (!file_exists($newpath)) {
              mkdir($newpath, 0777, true);
          }
          $allowedExts = array("gif", "jpeg", "jpg", "png");
          $temp = explode(".", $_FILES["file"]["name"]);
          $extension = end($temp);
  
          if ((($_FILES["file"]["type"] == "image/gif")
              || ($_FILES["file"]["type"] == "image/jpeg")
              || ($_FILES["file"]["type"] == "image/jpg")
              || ($_FILES["file"]["type"] == "image/pjpeg")
              || ($_FILES["file"]["type"] == "image/x-png")
              || ($_FILES["file"]["type"] == "image/png"))
              &amp;&amp; ($_FILES["file"]["size"] &lt; 20000000)
              &amp;&amp; in_array($extension, $allowedExts)) {
                if ($_FILES["file"]["error"] &gt; 0) {
                  echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br&gt;";
                } else {
                  echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;";
                  echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;";
                  echo "Size: " . ($_FILES["file"]["size"] / 5000) . " kB&lt;br&gt;";
                  echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br&gt;";
                  if (file_exists($newpath. $_FILES["file"]["name"])) {
                    echo $_FILES["file"]["name"]. " already exists. ";
                  } else {
                      //rename
                      $temp2 = explode(".", $_FILES["file"]["name"]);
  
                      $dir_name = substr($cfn, 0, 15);
                      $rn_fn = $dir_name. '_'.$image.'.'.end($temp2);
                      $full_path = $newpath.$rn_fn;
                      $p2db = 'funds/deeds/'.$cfn.$rn_fn;
                      move_uploaded_file($_FILES["file"]["tmp_name"], $full_path);
                      $img_name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $rn_fn);
                      $img_name_we = $rn_fn;
                      $user = $_SESSION['MM_Username'];
                      $insert = mysql_query("INSERT INTO imgs(fid, image, img_name, img_name_we, path, i_user) VALUES('$fund_id','$i_image','$img_name','$img_name_we','$p2db', '$user')") or die(mysql_error());
                      echo "&lt;h3&gt;"."File Uploaded!". "&lt;/h3&gt;";
                      echo '&lt;a href="index.php?fund_id='.$fund_id.'"&gt;'.'Go back&lt;/a&gt;';
                      $photoid= mysql_insert_id();
                      echo "&lt;br&gt;&lt;br&gt;";
                      die();
                  }
              }
          } else {
              echo "Invalid file";
          }
      }
  }
  </code></pre>
  
  <p>Whenever a user uploading a large image (like 3000x4000 &amp; File size 4.3MB) script give 'Invalid File' error.</p>
  
  <p>I already set <code>upload_max_filesize</code> &amp; <code>post_max_size</code> to 12M, <code>max_input_time</code> &amp; <code>max_execution_time</code> to 300</p>
  
  <p>What do you think?</p>