Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/242130-problem-in-uploading-multiple-images/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.