petenaylor Posted August 25, 2011 Share Posted August 25, 2011 Hi all I have a script that takes up to 3 images and resizes them. It works except for if you try and upload images over roughly 500kb. I then get the message: Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) Here's a snippet of the code for one image: // Process image 1 : if(!empty($_FILES['image1']['name'])) { $imagelarge = $_FILES['image1']['tmp_name']; $imagelargemain = $_FILES['image1']['name']; $pathInfo = pathinfo($imagelargemain); $rand = rand(1, 100000000000000); $name = $rand . '.' . $pathInfo['extension']; $src = imagecreatefromjpeg($imagelarge); list($width,$height)=getimagesize($imagelarge); if ($width > $height) { $newwidth=600; $newheight=($height/$width)*$newwidth; } elseif ($height > $width) { $newheight=400; $newwidth=($width/$height)*$newheight; } $center_x = (600/2)-($newwidth/2); $center_y = (400/2)-($newheight/2); $tmp=imagecreatetruecolor(600,400); $white = imagecolorallocate($tmp, 255, 255, 255); imagefill($tmp, 0, 0, $white); imagecopyresampled($tmp,$src,$center_x,$center_y,0,0,$newwidth,$newheight,$width,$height); $filename = WEB_UPLOAD."images/adverts/". $name; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); $image_sql = mysql_query("UPDATE `adverts` SET image1 ='".$name."' WHERE id='".$insertid."'") or die ("Error updating database"); } Any ideas why this happens? Many thanks Pete Quote Link to comment https://forums.phpfreaks.com/topic/245690-image-upload-script-exhausting-memory/ Share on other sites More sharing options...
etnastyles Posted August 25, 2011 Share Posted August 25, 2011 this might not have anything to do with your script it might be worth checking and increasing your max upload limit and i would increase the script timeout limit too - do this in your php.ini Quote Link to comment https://forums.phpfreaks.com/topic/245690-image-upload-script-exhausting-memory/#findComment-1261894 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.