ljones Posted August 26, 2007 Share Posted August 26, 2007 Could one of you kind folks have a look at this and give me some insight as to why, when the uploaded image is say greater than 3.5 mb, the lowRes image does not get created? A temp dir is created, the uploaded file gets moved there (no matter it's size), the doResize function gets called pointing back to the temp dir and file to create the thumbnail, this works (no matter it's size). Now the problem, when the doResize is called to create the lowRes image, if the file is below 3.5mb, it works, but when it's above, it does not. The obvious thing is there is a max limit of some sort, but here's the kicker, the file (no matter it's size) is has already been moved to the temp dir and resides on the server. Now if the function is just pointing to the file already residing on the server, why won't it create the lowRes? Thanks in advance, any help would be greatly appreciated. $temp_file_dir = "./temp_file/"; $file_dir = "../fscommand/media/images/images/"; $resize_Image = 800; $imageQuality = 90; $thumb_dir ="../fscommand/media/images/thumbnails/"; $resize_Thumbnail = 100; $thumbQuality = 75; //create the directory if doesn't exists (should have write permissons) if(!is_dir($temp_file_dir)) mkdir($temp_file_dir, 0666); //////////// function doResize($srcDirectory, $targetDirectory, $targetSize, $targetQuality) { $img = imagecreatefromjpeg($srcDirectory); $width = imagesx($img); $height = imagesy($img); //////////////////////////////////////////// if($width>$height){ $new_width = $targetSize; $new_height = floor( $height * ( $targetSize / $width ) ); }else if($height>$width){ $new_width = floor( $width * ( $targetSize / $height ) ); $new_height = $targetSize; }else if($height==$width){ $new_width = $targetSize; $new_height = $targetSize; } // create a new temporary image $image_resized = imagecreatetruecolor( $new_width, $new_height ); // copy and resize old image into new image imagecopyresampled( $image_resized, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); imagejpeg($image_resized, $targetDirectory, $targetQuality); // free memory used imagedestroy($image_resized); imagedestroy($img); } //move the uploaded file move_uploaded_file($_FILES['Filedata']['tmp_name'], $temp_file_dir.$_FILES['Filedata']['name']); // doResize($temp_file_dir.$_FILES['Filedata']['name'], $thumb_dir.$_FILES['Filedata']['name'], $resize_Thumbnail); doResize($temp_file_dir.$_FILES['Filedata']['name'], $file_dir.$_FILES['Filedata']['name'], $resize_Image); Quote Link to comment https://forums.phpfreaks.com/topic/66762-move_uploaded_file-imagecreatefromjpeg-max-limit-but-its-already-on-server/ Share on other sites More sharing options...
ljones Posted August 26, 2007 Author Share Posted August 26, 2007 I put this line in at the beginning: ini_set("memory_limit","50M"); and it does the trick, is this the good way to go? Quote Link to comment https://forums.phpfreaks.com/topic/66762-move_uploaded_file-imagecreatefromjpeg-max-limit-but-its-already-on-server/#findComment-334677 Share on other sites More sharing options...
lightningstrike Posted August 26, 2007 Share Posted August 26, 2007 Yes, that's the only solution I can think of other than to use another piece of software which consumes less memory. Quote Link to comment https://forums.phpfreaks.com/topic/66762-move_uploaded_file-imagecreatefromjpeg-max-limit-but-its-already-on-server/#findComment-334679 Share on other sites More sharing options...
ljones Posted August 27, 2007 Author Share Posted August 27, 2007 Thanks for the reply lightningstrike, Just so I have this straight, the reason is because jpgs are compressed and when imagecreatefromjpeg() is run it needs a huge amount of memory to unpack the jpg and resample it, depending on the original size. Is there a way to dynamically check the amount of memory needed? Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/66762-move_uploaded_file-imagecreatefromjpeg-max-limit-but-its-already-on-server/#findComment-334835 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.