SrinivasM Posted December 7, 2009 Share Posted December 7, 2009 I am trying to upload 2.5MB ptotos using the following code,but they are not getting uploaded,using the same code photos of 1.6MB are getting uploded.I am showing the code I am using: //Upload Photos if(isset($_POST['submit'])) { if (isset ($_FILES['pictures'])) { ini_set("memory_limit","12M"); $i = 0; //Looping through elements of array foreach ($_FILES["pictures"]["error"] as $key => $error) { //Checking file extensions and photo size if ((($_FILES['pictures']['type'][$i] == "image/gif") || ($_FILES['pictures']['type'][$i] == "image/jpeg") || ($_FILES['pictures']['type'][$i] =="image/pjpeg"))&& ($_FILES['pictures']['size'][$i] < 2500000)) { // check if user actually put something in the file input field. $filesize = $_FILES['pictures']['size'][$i]; //check the photo size if ($filesize != 0) { $imagename = $_FILES['pictures']['name'][$i]; $source = $_FILES['pictures']['tmp_name'][$i]; $target = "picture/".$imagename; $imagepath = $imagename; $save = "picture/" . $imagepath; //This is the new file you saving $file = "picture/" . $imagepath; //This is the original file //Check for duplicates if(file_exists($file)) { $errmsg_arr[] = "File already exists"; $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); //Redirect to upload form header("location: upLoadform.php"); exit; } move_uploaded_file($source, $target); list($width, $height) = getimagesize($file) ; $modwidth = 500; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION $image_type = strrchr($file, "."); //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': $image = imagecreatefromjpeg($file) ; break; case '.jpeg': $image = imagecreatefromjpeg($file) ; break; case '.gif': $image = imagecreatefromgif($file); break; default: die; break; } //$image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': imagejpeg($tn, $save, 100) ; break; case '.jpeg': imagejpeg($tn, $save, 100) ; break; case '.gif': imagegif($tn, $save, 100) ; break; default: die; break; } $save1 = "picturethumb/" . $imagepath; //This is the new file you saving $file = "picture/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 100; $modheight = 100; $tn = imagecreatetruecolor($modwidth,$modheight) ; //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': $image = imagecreatefromjpeg($file) ; break; case '.jpeg': $image = imagecreatefromjpeg($file) ; break; case '.gif': $image = imagecreatefromgif($file); break; default: die; break; } //$image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0,$modwidth, $modheight, $width, $height) ; //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': imagejpeg($tn, $save1, 100) ; break; case '.jpeg': imagejpeg($tn, $save1, 100) ; break; case '.gif': magegif($tn, $save1, 100) ; break; default: die; break; } $i++; } else { $errmsg_arr[] = "Failed to upload file"; $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); //Redirect to upload form header("location: upLoadform.php"); exit; } } } } } $errmsg_arr[] = "File uploaded sucessfully"; $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); //Redirect to upload form header("location: upLoadform.php"); I am doing website for the first time.Is anything wrong with my code. Any help will be appreciated. Thanks in advance. Srinivas. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 7, 2009 Share Posted December 7, 2009 I am trying to upload 2.5MB ptotos using the following code,but they are not getting uploaded,using the same code photos of 1.6MB are getting uploded.I am showing the code I am using: //Upload Photos if(isset($_POST['submit'])) { if (isset ($_FILES['pictures'])) { ini_set("memory_limit","12M"); $i = 0; //Looping through elements of array foreach ($_FILES["pictures"]["error"] as $key => $error) { //Checking file extensions and photo size if ((($_FILES['pictures']['type'][$i] == "image/gif") || ($_FILES['pictures']['type'][$i] == "image/jpeg") || ($_FILES['pictures']['type'][$i] =="image/pjpeg"))&& ($_FILES['pictures']['size'][$i] < 2500000)) { // check if user actually put something in the file input field. $filesize = $_FILES['pictures']['size'][$i]; //check the photo size if ($filesize != 0) { $imagename = $_FILES['pictures']['name'][$i]; $source = $_FILES['pictures']['tmp_name'][$i]; $target = "picture/".$imagename; $imagepath = $imagename; $save = "picture/" . $imagepath; //This is the new file you saving $file = "picture/" . $imagepath; //This is the original file //Check for duplicates if(file_exists($file)) { $errmsg_arr[] = "File already exists"; $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); //Redirect to upload form header("location: upLoadform.php"); exit; } move_uploaded_file($source, $target); list($width, $height) = getimagesize($file) ; $modwidth = 500; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION $image_type = strrchr($file, "."); //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': $image = imagecreatefromjpeg($file) ; break; case '.jpeg': $image = imagecreatefromjpeg($file) ; break; case '.gif': $image = imagecreatefromgif($file); break; default: die; break; } //$image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': imagejpeg($tn, $save, 100) ; break; case '.jpeg': imagejpeg($tn, $save, 100) ; break; case '.gif': imagegif($tn, $save, 100) ; break; default: die; break; } $save1 = "picturethumb/" . $imagepath; //This is the new file you saving $file = "picture/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 100; $modheight = 100; $tn = imagecreatetruecolor($modwidth,$modheight) ; //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': $image = imagecreatefromjpeg($file) ; break; case '.jpeg': $image = imagecreatefromjpeg($file) ; break; case '.gif': $image = imagecreatefromgif($file); break; default: die; break; } //$image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0,$modwidth, $modheight, $width, $height) ; //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': imagejpeg($tn, $save1, 100) ; break; case '.jpeg': imagejpeg($tn, $save1, 100) ; break; case '.gif': magegif($tn, $save1, 100) ; break; default: die; break; } $i++; } else { $errmsg_arr[] = "Failed to upload file"; $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); //Redirect to upload form header("location: upLoadform.php"); exit; } } } } } $errmsg_arr[] = "File uploaded sucessfully"; $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); //Redirect to upload form header("location: upLoadform.php"); I am doing website for the first time.Is anything wrong with my code. Any help will be appreciated. Thanks in advance. Srinivas. Create a file named .htaccess in your web root with this to make sure your server isn't limiting file upload size: upload_max_filesize php_value post_max_size 30M php_value upload_max_filesize 10M Or modify PHP.ini and place those values in yourself. Also, note 2.5MBs is larger than 2,500,000 bytes. 1024x2500 = 2,560,000.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.