darknessmdk Posted June 9, 2008 Share Posted June 9, 2008 I have built a multiple file upload for an image gallery, one of the requirements is to resize any images that exceed a width of 500px or height of 400px, My script works great as long as the files are under 1MB after that I get a half displayed page with this error "Allowed memory size of 20971520 bytes exhausted (tried to allocate 12288 bytes)" and it references the line that imagecreatefromjpeg() is on. I have had my host (hostmysite) raise the memory_limit setting to 20MB, they will go no higher. Any idea why this is an issue with a 1MB jpeg? foreach ($_FILES["photofile"]["error"] as $key => $error) { if($error == UPLOAD_ERR_OK){ $logo = $_FILES['photofile']['name'][$key];; $logo_ext = strtolower(substr($logo,strrpos($logo,"."))); $result = mysql_query("INSERT into gallery(image, caption, section, subsection)VALUES('$image', '$caption', '$section', '$subsection')"); $id=mysql_insert_id(); $tmp_name = $_FILES["photofile"]["tmp_name"][$key]; $name = $_FILES["photofile"]["name"][$key]; $random = rand(1, 6); //:::File Resize:::\\ $uploadedfile = $tmp_name; $src = imagecreatefromjpeg($uploadedfile); // get size of image list($width,$height)=getimagesize($uploadedfile); if ($width > $height) { $target_width=500; $ratio = $target_width/$width; $newwidth = $width * $ratio; $newheight = $height * $ratio; } else { $target_height = 400; $ratio = $target_height/$height; $newwidth = $width * $ratio; $newheight = $height * $ratio; } $tmp=imagecreatetruecolor($newwidth,$newheight); // resize imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // save resized //$fname = explode('.', $_FILES["photofile"]["name"]); //$filename = $fname[0] . "resized" . ".jpg"; imagejpeg($tmp,$uploadedfile,100); imagedestroy($src); imagedestroy($tmp); //:::End File Resize:::\\ move_uploaded_file($uploadedfile, "../gallery/photo".$id."".$random."".$logo_ext.""); // Sets permissions 644 chmod("../gallery/photo".$id."".$random."".$logo_ext."", 0644); //$image = "propimg/"; $query2= mysql_query("UPDATE gallery SET image='photo".$id."".$random."". $logo_ext ."' WHERE id = '$id'"); //$checked = $_POST['type2']; //foreach ($checked as $type) { // } } } if($result == TRUE) { echo "<span style='message'>Your photos have been uploaded!</span>"; } else { echo "<span style='error'>There was a problem uploading, Try again</span>"; } }else{ echo ""; } ?> Link to comment https://forums.phpfreaks.com/topic/109352-solved-imagecreatefromjpeg-memory-issue/ Share on other sites More sharing options...
tippy_102 Posted June 9, 2008 Share Posted June 9, 2008 There is quite a bit of discussion on memory usage on the imagecreatefromjpeg page on php.net ( http://ca.php.net/imagecreatefromjpeg ). Have you tried to change the limit using ini_set? Link to comment https://forums.phpfreaks.com/topic/109352-solved-imagecreatefromjpeg-memory-issue/#findComment-560885 Share on other sites More sharing options...
darknessmdk Posted June 9, 2008 Author Share Posted June 9, 2008 No I haven't tried that yet, my host said they raised the memory limit to their max so I didn't bother doing it through php, I will this though. Link to comment https://forums.phpfreaks.com/topic/109352-solved-imagecreatefromjpeg-memory-issue/#findComment-561150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.