garydt Posted August 17, 2007 Author Share Posted August 17, 2007 I took the echo out of the CP function because i thought when it echos something to the screen it stops executing the rest of the code. Either way it still doesn't resize larger images ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326574 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 it must be the execution timeingout.. how long does it take for the script to run..? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326579 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 it depends on how large the image is, anywhere from 40 seconds upwards. Is there a command for timing the run-time? In thde php.ini the max-execution-time is 300. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326587 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 OK, lts rethink this.. the routine does 3 things 1. upload the image 2. create a thumbnail 3. create a standard size image (no larger than 300x300) correct ? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326592 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 yep, correct. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326595 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 OK new style i may of messed the paths up but the logic follows this create the 300x300 then from that create the 140x140 using the same function so it will upload create the 300 image then open the 300 image and create the 140 image.. this should reduce the time and memory required.. <?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('./uploads/'.$fieldname['name'], './smallpics/',300); rename("smallpics/".$fieldname['name'], "smallpics/".$user.$a.$fieldname['name']); $smallpics = './smallpics/'.$user.$a.$fieldname['name']; CP("2"); resizeimage("smallpics/".$user.$a.$fieldname['name']), './thumbnails/',140); rename("thumbnails/".$fieldname['name'], "thumbnails/".$user.$a.$fieldname['name']); $smallimage = './thumbnails/'.$user.$a.$fieldname['name']; CP("3"); unlink($uploadedphoto); function CP($Num) { echo "CP: $Num<br />"; ob_flush(); flush(); set_time_limit ( 0 ); } function resizeimage($name, $topath, $maxSize) { //$filename = './uploads/'.$name; $filename = $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 / $maxSize; }else { $im_divice = $im_height / $maxSize; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image ini_set('memory_limit', '500M'); CP("startImage"); $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, $topath.$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/3/#findComment-326599 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 Thanks, I'll try that. What does the CP("startImage") do? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326625 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 nothing much echo's CP: startImage to the page flushs the page and resets the timer.. i used a it a few times so created i function instead CP function function CP($Num) { echo "CP: $Num<br />"; ob_flush(); flush(); set_time_limit ( 0 ); } Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326637 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 i got- Fatal error: Cannot redeclare resizeimage() (previously declared in /homepages/3/d209077294/htdocs/uplodsmalpic2.php:141) in /homepages/3/d209077294/htdocs/uplodsmalpic2.php on line 210 Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326696 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 erm... thats weird ? is this in a class ? 60 lines apart! Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326700 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 sory, my mistake, i didn't take old resizeimage function. i try again.......... Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326708 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 only cp:1 is coming up Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326721 Share on other sites More sharing options...
garydt Posted August 17, 2007 Author Share Posted August 17, 2007 What shall i try now? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-326744 Share on other sites More sharing options...
garydt Posted August 19, 2007 Author Share Posted August 19, 2007 I'm still having problems. Do you think it could be anything with the server like it's running an out-of-date GD Library version so it can't resize large images but small ones are ok, or something else? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328007 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 i don't think its the GDversion but i would suggest breaking the script up into 3 scripts 1. upload 2. create 300 image 3. create 140 image (from the 300 image) maybe link them via header("Location: next.php); see if that helps, as you are putting a lot of stress on server with 1 script.. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328015 Share on other sites More sharing options...
garydt Posted August 19, 2007 Author Share Posted August 19, 2007 I tried that with your script where it just resizes 3 images - i tried it with 1 image and it still failed. i've been looking at the phpinfo for my server and it got- max-execution-time 30 memory_limit 8m post-max-size 8m so does that mean it isn't reading my php.ini file? could that be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328053 Share on other sites More sharing options...
garydt Posted August 19, 2007 Author Share Posted August 19, 2007 Shouldn't my php.ini be overriding the server's default settings? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328092 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 increase those at a guess max-execution-time 300 memory_limit 32m post-max-size 16m Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328122 Share on other sites More sharing options...
garydt Posted August 19, 2007 Author Share Posted August 19, 2007 my php.ini isn't over-riding the server's default settings. What can i do? Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328169 Share on other sites More sharing options...
phpknight Posted August 19, 2007 Share Posted August 19, 2007 You definitely need a lot of memory to do that. I do something similar with 5000x5000 pixels (PNG), it takes 189 MB. Even 1000x1000 pixels took 90 MB. Try these three scenarios--for all three, do not use the temp folder--upload somewhere permanent. This will help narrow down the issue. You can also try them in reverse order. Save the file before doing any resizing. BTW, if the memory limits are the problem, you should have a fatal PHP error in a file. Make sure log_errors is on so you can read that. A 500 server error sounds like a non-php issue. #1 1.) Upload a huge image using FTP 2.) With PHP, open it. Do not resize it. 3.) Save it in another location. If this works, do this: #2 1.) Same as before. 2.) With PHP, open it. Resize it. 3.) Save it in another location. If this works, do this: 1.) Upload the image using PHP. 2.) Save it in a non-temp location. 3.) Reopen it, resize it, and save it in another location. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328180 Share on other sites More sharing options...
phpknight Posted August 19, 2007 Share Posted August 19, 2007 Also, you cannot override post_max_size, but you should be able to do the other two with set_ini calls without a problem. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328182 Share on other sites More sharing options...
garydt Posted August 19, 2007 Author Share Posted August 19, 2007 I tried the 1st scenario. Php wouldn't open a big image, just got the small red X even when i put - ini_set('memory_limit', '500M'); ini_set('max_execution_time', '300'); at the start of the script. What does this point to? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328283 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Share Posted August 20, 2007 Okay, let's see if we can get that narrowed down. At this point, then, is it safe to say the issue actually might not be uploading but something else? Put just the short code up here for scenario 1. I will try that on my server and see what the issue is. Also, set memory_limit and that max one. But, do this after. $myResult=ini_get('memory_limit'); var_dump($myResult); Do the same with the other one. If it dumps false, the change is not taking. If it dumps your numbers, then you are good. Do this and comment out your other code to see if the changes work. For the time, use this one: set_time_limit (200); Also, don't put the M. Put the number: ini_set('memory_limit', "250000000"); $testmem=ini_get('memory_limit'); print "memlimit is $testmem"; Jim Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328482 Share on other sites More sharing options...
garydt Posted August 20, 2007 Author Share Posted August 20, 2007 Thanks, I did that and it comes up with- memlimit is 250000000string(9) "250000000" still the large image doesn't open, only a small one, This is the code i did <?php ini_set('max_execution_time', '300'); ini_set('memory_limit', "250000000"); $testmem=ini_get('memory_limit'); print "memlimit is $testmem"; $myResult=ini_get('memory_limit'); var_dump($myResult); $pic = './uploads/img1.jpg'; print $pic; $pic1 = './thumbnails/garydt88Picture 003.jpg'; print $pic1; ?> <body> <img src="<?php print $pic; ?>" border="0" /> <img src="<?php print $pic1; ?>" border="0" /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328689 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Share Posted August 20, 2007 I don't see where you are opening them. It probably has nothing to do with this, but I'd avoid spaces in filenames just to be safe. Put the code up here that you are using to do that. Would you be willing to use other code as well? I could post mine up here and see if that makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/64820-weird-problem-with-uploading-big-images/page/3/#findComment-328764 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.