wrathican Posted May 21, 2008 Share Posted May 21, 2008 ive created a simple image gallery: the user can upload an image and the script will create a thubnail and add it to the DB a user recently complained to me that he gets this error: Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 2592 bytes) in /home/fhlinux162/m/members.ls12style.co.uk/user/htdocs/includes/functions.php on line 146 it seems that is is just this user that gets this error. i asked him to mail me one of the images he was trying to use so i could try it. i got the same error it seems as though the GD functions do not recognise the image as a propper image and the script just fails. heres the function that handles the thumbnail creation: <?php function createThumb($result, $picWidth, $imgDir) { $poo = array(); if ($result == false) { //file could not be uploaded $poo[0] = false; $poo[1] = 1; return $poo; }else{ //file was uploaded. create thumbnail //pathinfo $file = pathinfo($result); //find the .ext $ext = $file['extension']; //strip .ext to lower $ext = strtolower($ext); //get image sizes $sizes = getimagesize($result); //ratio $ratio = $sizes[0]/$sizes[1]; //create new height $newHeight = round($picWidth/$ratio); //create true colour image $srcImg = imagecreatetruecolor($picWidth, $newHeight); if($ext == 'jpg' || $ext == 'jpeg') { $tmpImg = imagecreatefromjpeg($result); }elseif($ext == 'png') { $tmpImg = imagecreatefrompng($result); }elseif($ext == 'gif') { $tmpImg = imagecreatefromgif($result); }else{ $poo[0] = false; $poo[1] = 2; return $poo; } //create destination image filename //get filename $name = $file['basename']; //dest filename $dstFile = $imgDir . $name; imagecopyresampled($srcImg, $tmpImg, 0, 0, 0, 0, $picWidth, $newHeight, $sizes[0], $sizes[1]); //save image if($ext == 'jpg' || $ext == 'jpeg') { imagejpeg($srcImg, $dstFile, 100); }elseif($ext == 'png') { imagepng($scrImg, $dstFile, 100); }elseif($ext == 'gif') { imagegif($srcImg, $dstFile, 100); }else{ $poo[0] = false; $poo[1] = 3; return $poo;; } $killSrc = imagedestroy($srcImg); $killTmp = imagedestroy($tmpImg); if($killSrc != false && $killTmp != false){ $killOld = unlink($result); if($killOld != false){ return $name; }else{ $poo[0] = false; $poo[1] = 4; return $poo; } }else{ $poo[0] = false; $poo[1] = 5; return $poo; } } } ?> any suggestions are welcome Link to comment https://forums.phpfreaks.com/topic/106605-image-gallery-problem/ Share on other sites More sharing options...
darknessmdk Posted June 9, 2008 Share Posted June 9, 2008 I'm also having a similar issue, however it only happens when I try to upload an image thats 1MB or higher Link to comment https://forums.phpfreaks.com/topic/106605-image-gallery-problem/#findComment-560869 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.