upendra470 Posted July 16, 2011 Share Posted July 16, 2011 I can upload a number of images in localhost but when i uploaded my site on remote server then on multiple uploading of images it shows this error Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 10240 bytes) in /home/ihroydc/public_html/control/addgallery.php on line 51 here is my code <?php ob_start(); ?> <?php include "session.php"; include "connect.php"; if(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH']>8097152){ echo "<script type = 'text/javascript'>alert('Upload files is too large. Cannot add to the gallery'); window.location = 'gallery.php';</script>"; exit(); } else{ $n_width = 100; $n_height = 100; if(count($_FILES["image_id"]["name"]) > 0){ for($j=0; $j < count($_FILES["image_id"]["name"]); $j++){ if ((($_FILES["image_id"]["type"][$j] == "image/gif") || ($_FILES["image_id"]["type"][$j] == "image/jpeg") || ($_FILES["image_id"]["type"][$j] == "image/pjpeg")) && ($_FILES["image_id"]["size"][$j] < 40000000)) { if ($_FILES["image_id"]["error"][$j] > 0) { echo "Return Code: " . $_FILES["image_id"]["error"][$j] . "<br />"; } else { if (file_exists("/home/ihroydc/public_html/control/upload/compressed/" . $_FILES["image_id"]["name"][$j])) { echo "<script type = 'text/javascript'>alert('Image already exist'); window.location = 'gallery.php';</script>"; } else { move_uploaded_file($_FILES["image_id"]["tmp_name"][$j], "/home/ihroydc/public_html/control/upload/gallery/" . $_FILES["image_id"]["name"][$j]); echo "Stored in: " . "upload/gallery/" . $_FILES["image_id"]["name"][$j]; $tsrc = "/home/ihroydc/public_html/control/upload/thumbs/".$_FILES["image_id"]["name"][$j]; $im = imagecreatefromjpeg("/home/ihroydc/public_html/control/upload/gallery/".$_FILES["image_id"]["name"][$j]); $width = imagesx($im); $height = imagesy($im); $newimage = imagecreatetruecolor($n_width,$n_height); imagecopyresampled($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); imagejpeg($newimage, $tsrc); chmod("$tsrc", 0777); $im_info = getimagesize("/home/ihroydc/public_html/control/upload/gallery/".$_FILES["image_id"]["name"][$j]); $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; $im_divicew = $im_width / 800; $im_diviceh = $im_height / 600; $thumb_width = $im_width / $im_divicew; $thumb_height = $im_height / $im_diviceh; $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $im, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); $csrc = "/home/ihroydc/public_html/control/upload/compressed/".$_FILES["image_id"]["name"][$j]; imagejpeg($thumb,$csrc, 100); @unlink("/home/ihroydc/public_html/control/upload/gallery/".$_FILES["image_id"]["name"][$j]); } } } else { echo "Invalid file"; } } } } $category = $_POST['category']; $desc = $_POST['desc']; for($j=0; $j < count($_FILES["image_id"]["name"]); $j++){ $pic_name = $_FILES["image_id"]["name"][$j]; $sql= "insert into gallery (category, pic_desc, pic_name) values('$category', '$desc', '$pic_name')"; $result = mysql_query($sql) or die(mysql_error()); } if($result){ echo "<script type = 'text/javascript'>alert('Picture uploaded sucessfully'); window.location = 'gallery.php';</script>"; //echo "<h4 style='color:green;'>Picture uploaded sucessfully</h4>"; //echo "<meta http-equiv=\"refresh\" content=\"1;URL=gallery.php\" />"; //header("location: galleryadded.php"); } else{ echo " <script type = 'text/javascript'>alert('Image cannot be added. It already exist'); window.location = 'gallery.php'; </script>"; } ?> <?php ob_flush(); ?> [\code] Any help would be appreciated. Thanx Quote Link to comment https://forums.phpfreaks.com/topic/242130-problem-in-uploading-multiple-images/ Share on other sites More sharing options...
TeNDoLLA Posted July 16, 2011 Share Posted July 16, 2011 I googled it for you, people should learn to use google http://www.tech-recipes.com/rx/777/solve-php-fatal-error-allowed-memory-size-of-8388608-bytes-exhausted-tried/ Quote Link to comment https://forums.phpfreaks.com/topic/242130-problem-in-uploading-multiple-images/#findComment-1243498 Share on other sites More sharing options...
PFMaBiSmAd Posted July 16, 2011 Share Posted July 16, 2011 The GD image functions operate on an uncompressed bitmap version of the image (jpg, gif, png use data compression to reduce the file size) and require a relatively large amount of memory. Each of your image resources $im, $newimage, and $thumb should be destroyed, see imagedestroy, immediately after you are finished with each of them in the loop so that the memory taken by them is available for the rest of the code and for the next iteration of the loop. Quote Link to comment https://forums.phpfreaks.com/topic/242130-problem-in-uploading-multiple-images/#findComment-1243504 Share on other sites More sharing options...
TeNDoLLA Posted July 16, 2011 Share Posted July 16, 2011 Oh yeah PFMaBiSmAd is so right. Didn't even look the code this time and just googled the error. I take back my comment about that people shud learn to google. Quote Link to comment https://forums.phpfreaks.com/topic/242130-problem-in-uploading-multiple-images/#findComment-1243512 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.