MadTechie Posted August 15, 2007 Share Posted August 15, 2007 OK Good News and bad News Good News: I am at home and ran some tests, and it works Bad News: I didn't change much.. So i have PM'ed you a link to my test site it has a link to phpinfo() and the source code (little changes) files uploaded for you to test are:~ 1.1Mb File 2000x1303 (main file) 3.5Mb File 4000x2606 (doubled) 10.2mb File 8000x5212 (doubled) again Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-324943 Share on other sites More sharing options...
jishosan Posted August 15, 2007 Share Posted August 15, 2007 MadTechie is right on. Honestly, you wouldn't need more than about 60M or so for at 3500 pixel image, even if PHP creates a bitmap copy during the image resampling process. 80M should be enough, and 160M is probably overkill. I take it the memory_get_usage() line never executed or showed you any additional error message? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-324982 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 No, the memory_get_usage() line never executed or showed any additional error message. Thanks very much, MadTechie. I can see it should b working, i can't understand why my script doesn't always work I added the lines - ini_set('memory_limit', '500M'); set_time_limit ( 0 ); and i still get server error 500 or it says its not a jpeg when i try and upload/resize a large image. here's most of my script in case you spot something i've got wrong. Upload form- <form name="form1" id="Upload" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="POST"> <p> <input type="hidden" name="MAX_FILE_SIZE" value="2000000000"> </p> <h3> <input name="file" type="file" id="file" onchange="MM_showHideLayers('Layer1','','hide')" /> <span class="style1">for your photo</span> </h3> <p> <label> <input name="sent" type="hidden" id="sent" value="1" /> </label> </p> <h3 class="style7"> <input type="text" name="textfield" /> <span class="style2 style1">Add caption for the photo</span> </h3> <input name="submit" type="submit" id="submit" onclick="MM_showHideLayers('Layer1','','hide','Layer3','','show')" value="Upload your photo"> </p> <input type="hidden" name="MM_insert" value="form1"> </form> check if its a jpeg and resize image to 140pixels. if(isset($_POST['sent'])){ unset($submit); if (isset($_POST['sent'])) $submit = true; else die('Error: No file got sent'); if($_FILES['file']['name']) { $arr = getimagesize($_FILES['file']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['file']['tmp_name']); if($type == FALSE) { header("Location: uploadform2.php"); exit(); } elseif($type != 2) { header("Location: uploadform2.php"); exit(); } } $fieldname = $_FILES['file']; function resizeimage($name){ $filename = './uploads/'.$name; if(file_exists($filename)) { ini_set('memory_limit', '500M'); set_time_limit ( 0 ); $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 100px; max width: 100px if($im_width >= $im_height) { $im_divice = $im_width / 140; }else { $im_divice = $im_height / 140; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "thumbnails/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } After this it resizes the image to 300pixels and saves it to another folder. My phi.ini - upload_max_filesize: 20M max_execution_time: 300 memory_limit: 300M post_max_size: 55M SMTP: localhost extension=php_gd2.dll On the server it has GD 1.6.2 (FreeType, TTF library, GIF Read/Create, JPG, PNG, WBMP) is this ok? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325622 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 quick question/test have you tried saving the whole php file i created and tried it on your server with no changes ? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325646 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 just tried it and 3 failed! What does that mean? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325662 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 Page is timeing out.. on your code add if (ob_get_level() == 0) ob_start(); then after the upload add echo "upload done"; ob_flush(); flush(); set_time_limit ( 0 ); this will reset the timeout.. basically you are uploading and resizing in one timeout slot by adding the above the timeout will start again the echo can be "" but for testing have some text in their see if that helps.. i don't have access to my php.ini so i'm more limited Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325666 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 Thanks i did that and i got upload done Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2200 bytes) in /homepages/3/d209077294/htdocs/uplodsmalpic2.php on line 135 Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325690 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 try adding ini_set('memory_limit', '500M'); //overkill on line 135 (above the current line 135) Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325767 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 I've done that and now it just says 'upload done' Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325818 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 you could add echo "resize done"; ob_end_flush(); flush(); at the end of the script.. did it create the thumb nail ? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325829 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 No it didn't resize image. When i took out the flush script but left in the memory-limit 500 it came up with server error 500 again. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325838 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 just tried it and it resized image! i'lltry bigger images now Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325841 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 fingers crossed Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325842 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 got our hopes up too quickly. just tried a larger jpeg and it said it wasn't a jpeg! Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325847 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 can you post your latest script, i'll put it on my site and review it Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325851 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 just to check - i've put this after the file has been uploaded- if (ob_get_level() == 0) ob_start(); ob_flush(); flush(); set_time_limit ( 0 ); is that right? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325853 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 at start of the script if (ob_get_level() == 0) ob_start(); //only need once after the upload echo ""; //send something to page to restart timeout ob_flush(); flush(); set_time_limit ( 0 ); //reset timeout timer before the reading of the JPG (i think thats the 135 line) ini_set('memory_limit', '500M'); //overkill memory Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325856 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 resize and upload script if(isset($_POST['sent'])){ unset($submit); if (isset($_POST['sent'])) $submit = true; else die('Error: No file got sent'); if($_FILES['file']['name']) { $arr = getimagesize($_FILES['file']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['file']['tmp_name']); if($type == FALSE) { if ($num==1) { header("Location: uplodsmalpic3.php?picnum=1"); exit(); } if ($num==2) { header("Location: uplodsmalpic3.php?picnum=2"); exit(); } if ($num==3) { header("Location: uplodsmalpic3.php?picnum=3"); exit(); } if ($num==4) { header("Location: uplodsmalpic3.php?picnum=4"); exit(); } } elseif($type != 2) { if ($num==1) { header("Location: uplodsmalpic3.php?picnum=1"); exit(); } if ($num==2) { header("Location: uplodsmalpic3.php?picnum=2"); exit(); } if ($num==3) { header("Location: uplodsmalpic3.php?picnum=3"); exit(); } if ($num==4) { header("Location: uplodsmalpic3.php?picnum=4"); exit(); } } } $fieldname = $_FILES['file']; function resizeimage($name){ $filename = './uploads/'.$name; if(file_exists($filename)) { ini_set('memory_limit', '500M'); $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 140px; max width: 140px if($im_width >= $im_height) { $im_divice = $im_width / 140; }else { $im_divice = $im_height / 140; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "thumbnails/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } function resizelarger($name){ $filename = './uploads/'.$name; if(file_exists($filename)) { $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 300px; max width: 300px if($im_width >= $im_height) { $im_divice = $im_width / 300; }else { $im_divice = $im_height / 300; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "smallpics/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } // make a note of the directory that will recieve the uploaded file // full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; $uploadsDirectory = './uploads/'; //Upload image $uploadFilename = $uploadsDirectory.$fieldname['name']; // now let's move the file to its final location and allocate the new filename to it move_uploaded_file($fieldname['tmp_name'], $uploadFilename); $uploadsDirectory = './uploads/'; $uploadedphoto = $uploadsDirectory.$fieldname['name']; $user = $_SESSION['MM_Username']; if (ob_get_level() == 0) ob_start(); ob_flush(); flush(); set_time_limit ( 0 ); $a = rand(1,99); resizeimage($fieldname['name']); rename("thumbnails/".$fieldname['name'], "thumbnails/".$user.$a.$fieldname['name']); $smallimage = './thumbnails/'.$user.$a.$fieldname['name']; resizelarger($fieldname['name']); rename("smallpics/".$fieldname['name'], "smallpics/".$user.$a.$fieldname['name']); $smallpics = './smallpics/'.$user.$a.$fieldname['name']; unlink($uploadedphoto); Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325859 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 updated resize and upload script if(isset($_POST['sent'])){ unset($submit); if (isset($_POST['sent'])) $submit = true; else die('Error: No file got sent'); if($_FILES['file']['name']) { $arr = getimagesize($_FILES['file']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['file']['tmp_name']); if($type == FALSE) { if ($num==1) { header("Location: uplodsmalpic3.php?picnum=1"); exit(); } if ($num==2) { header("Location: uplodsmalpic3.php?picnum=2"); exit(); } if ($num==3) { header("Location: uplodsmalpic3.php?picnum=3"); exit(); } if ($num==4) { header("Location: uplodsmalpic3.php?picnum=4"); exit(); } } elseif($type != 2) { if ($num==1) { header("Location: uplodsmalpic3.php?picnum=1"); exit(); } if ($num==2) { header("Location: uplodsmalpic3.php?picnum=2"); exit(); } if ($num==3) { header("Location: uplodsmalpic3.php?picnum=3"); exit(); } if ($num==4) { header("Location: uplodsmalpic3.php?picnum=4"); exit(); } } } $fieldname = $_FILES['file']; function resizeimage($name){ $filename = './uploads/'.$name; if(file_exists($filename)) { ini_set('memory_limit', '500M'); $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 140px; max width: 140px if($im_width >= $im_height) { $im_divice = $im_width / 140; }else { $im_divice = $im_height / 140; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "thumbnails/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } function resizelarger($name){ $filename = './uploads/'.$name; if(file_exists($filename)) { $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 300px; max width: 300px if($im_width >= $im_height) { $im_divice = $im_width / 300; }else { $im_divice = $im_height / 300; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "smallpics/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } // make a note of the directory that will recieve the uploaded file // full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; $uploadsDirectory = './uploads/'; //Upload image $uploadFilename = $uploadsDirectory.$fieldname['name']; // now let's move the file to its final location and allocate the new filename to it move_uploaded_file($fieldname['tmp_name'], $uploadFilename); $uploadsDirectory = './uploads/'; $uploadedphoto = $uploadsDirectory.$fieldname['name']; $user = $_SESSION['MM_Username']; echo "upload done"; ob_flush(); flush(); set_time_limit ( 0 ); $a = rand(1,99); resizeimage($fieldname['name']); rename("thumbnails/".$fieldname['name'], "thumbnails/".$user.$a.$fieldname['name']); $smallimage = './thumbnails/'.$user.$a.$fieldname['name']; resizelarger($fieldname['name']); rename("smallpics/".$fieldname['name'], "smallpics/".$user.$a.$fieldname['name']); $smallpics = './smallpics/'.$user.$a.$fieldname['name']; unlink($uploadedphoto); Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325867 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 Just tried it again and again it went to the page saying it isn't a jpeg. Grrrrr! Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325870 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 revised (few changes) i added some CheckPoints it should display something ie 1 1.1 2 etc let me know what it gets to.. <?php if(isset($_POST['sent'])) { unset($submit); if (isset($_POST['sent'])) { $submit = true; }else{ die('Error: No file got sent'); } if($_FILES['file']['name']) { $arr = getimagesize($_FILES['file']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['file']['tmp_name']); if($type == FALSE) { header("Location: uplodsmalpic3.php?picnum=$num"); exit(); }elseif($type != 2){ header("Location: uplodsmalpic3.php?picnum=$num"); exit(); } } } $fieldname = $_FILES['file']; // make a note of the directory that will recieve the uploaded file // full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; $uploadsDirectory = './uploads/'; //Upload image $uploadFilename = $uploadsDirectory.$fieldname['name']; // now let's move the file to its final location and allocate the new filename to it move_uploaded_file($fieldname['tmp_name'], $uploadFilename); $uploadedphoto = $uploadsDirectory.$fieldname['name']; $user = $_SESSION['MM_Username']; CP("1"); $a = rand(1,99); resizeimage($fieldname['name']); CP("2"); rename("thumbnails/".$fieldname['name'], "thumbnails/".$user.$a.$fieldname['name']); $smallimage = './thumbnails/'.$user.$a.$fieldname['name']; CP("3"); resizelarger($fieldname['name']); rename("smallpics/".$fieldname['name'], "smallpics/".$user.$a.$fieldname['name']); $smallpics = './smallpics/'.$user.$a.$fieldname['name']; unlink($uploadedphoto); function CP($Num) { echo "CP: $Num<br />"; ob_flush(); flush(); set_time_limit ( 0 ); } function resizeimage($name) { $filename = './uploads/'.$name; if(file_exists($filename)) { ini_set('memory_limit', '500M'); $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 140px; max width: 140px if($im_width >= $im_height) { $im_divice = $im_width / 140; }else { $im_divice = $im_height / 140; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image ini_set('memory_limit', '500M'); CP("1.1"); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "thumbnails/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } function resizelarger($name) { $filename = './uploads/'.$name; if(file_exists($filename)) { $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 300px; max width: 300px if($im_width >= $im_height) { $im_divice = $im_width / 300; }else { $im_divice = $im_height / 300; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image ini_set('memory_limit', '500M'); CP("2.1"); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "smallpics/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325875 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 note i didn't see where $num was being set i assume that other code.. cleaned it up (i think) it should display 1 1.1 2 3 2.1 Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-325879 Share on other sites More sharing options...
garydt Posted August 16, 2007 Author Share Posted August 16, 2007 it didn't get to cp 2 Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-326186 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 i really can't see the fault.. the code i wrote seams to work on my server.. ??? will take a look in the morning Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-326210 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 if i take the echo out of the CP function i just get a blank white page after it has uploaded the image. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/2/#findComment-326499 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.