Bottyz Posted March 2, 2010 Share Posted March 2, 2010 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 https://forums.phpfreaks.com/topic/193915-fatal-error-allowed-memory-size-of-33554432-bytes-exhausted/ Share on other sites More sharing options...
Bottyz Posted March 2, 2010 Author Share Posted March 2, 2010 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 https://forums.phpfreaks.com/topic/193915-fatal-error-allowed-memory-size-of-33554432-bytes-exhausted/#findComment-1020494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.