Jump to content

Fatal error: Allowed memory size of 33554432 bytes exhausted


Bottyz

Recommended Posts

Hey all,

 

 

As previously posted i've been having some trouble getting a php download script working. I have made some progress and can now download small files. I have successfully downloaded a 66kb word document but when i've tried a 32.9mb zip file it is only 647 bytes and contains the following:

 

<b>Fatal error</b>: Allowed memory size of 33554432 bytes exhausted (tried to allocate 34560001 bytes) in <b>/home/a6964942/public_html/LHU/filedownload.php</b> on line <b>146</b><br />

 

I can download the file directly so i know i can download a file of that size, so the problem has to be somewhere within the script itself? The script i have setup for this is as follows:

 

// CODE FOR DB ACCESS and if user access granted continue...

// define the path to download folder plus assign the file name
$path = 'files/'.$filename;

// check that file exists and is readable
if (file_exists($path) && is_readable($path)) {

	// get the file size and send the http headers
	$size = filesize($path);

        // required for IE, otherwise Content-disposition is ignored
        if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');

	//content type
	switch(strtolower(substr(strrchr($filename,'.'),1)))
	{
          case "pdf": $mime="application/pdf"; break;
          case "mp3": $mime="audio/x-mp3"; break;
          case "zip": $mime="application/zip"; break;
          case "rar": $mime="application/zip"; break;
          case "tar": $mime="application/zip"; break;
          case "sit": $mime="application/zip"; break;
          case "doc": $mime="application/msword"; break;
          case "xls": $mime="application/vnd.ms-excel"; break;
          case "ppt": $mime="application/vnd.ms-powerpoint"; break;
          case "gif": $mime="image/gif"; break;
          case "png": $mime="image/png"; break;
          case "jpeg":$mime="image/jpg"; break;
          case "jpg": $mime="image/jpg"; break;
	  default: $mime="application/force-download";
	}

	header("Pragma: public");
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private",false);
	header("Content-Type: ".$mime);
	header("Content-Disposition: attachment; filename=\"".$filename."\";");
	header('Content-Transfer-Encoding: binary');
	header('Content-Length: '.$size);
	readfile("$path");

	if($logging == 1){
		$status = "Granted";
		include('logit.php');
	}
	exit;
}

 

Anybody know what could be the problem? Is there a limit to binary transfers?

 

 

Link to comment
Share on other sites

UPDATE:

 

I've found out that this message occurs because there is a default limited of 8mb in my php.ini.

 

I've added the following line to the beginning of my script

ini_set("memory_limit","100M");

 

this should now set the limit to 100mb. Everything now appears to work, zip file shows as 32.9mb but it only downloads part of it now. the original file size unpacked was 42,492,074 bytes but the downloaded zip's unpacked size is only 12,217,510 bytes.

 

Thanks for your help so far guys but now what????

 

Link to comment
Share on other sites

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.