I have developed a small image upload system with lot of customization like (renaming, thumbnail generating, validation).
All features are working perfectly except Images with high dimension (2000x2000 upwards).
I can't recognize the issue.
Following is my upload.php
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)> 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"))
&& ($_FILES["file"]["size"] < 20000000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 5000) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
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 "<h3>"."File Uploaded!". "</h3>";
echo '<a href="index.php?fund_id='.$fund_id.'">'.'Go back</a>';
$photoid= mysql_insert_id();
echo "<br><br>";
die();
}
}
} else {
echo "Invalid file";
}
}
}
Whenever a user uploading a large image (like 3000x4000 & File size 4.3MB) script give 'Invalid File' error.
I already set upload_max_filesize
& post_max_size
to 12M, max_input_time
& max_execution_time
to 300
What do you think?