Uploading file in php, memory limitation problem?

My client decided to transfer the website from a somewhat pleasant server to ... lets call it a less pleasant server.

The problem is that the file with 40 MB to upload and the memory limit on the server is 32. To make this even harder for me, they do not allow fopen ...

Also, if I reduce the file size to 20 MB, it works fine.

So my question is, what can I do - besides reducing the file size - to make this work?

thanks

EDIT: `

$fsize = filesize($file_path); $path_parts = pathinfo($file_path); $ext = strtolower($path_parts["extension"]); switch ($ext) { case "pdf": $ctype = "application/pdf"; break; case "exe": $ctype = "application/octet-stream"; break; case "zip": $ctype = "application/zip"; break; case "doc": $ctype = "application/msword"; break; case "xls": $ctype = "application/vnd.ms-excel"; break; case "ppt": $ctype = "application/vnd.ms-powerpoint"; break; case "gif": $ctype = "image/gif"; break; case "png": $ctype = "image/png"; break; case "jpeg": case "jpg": $ctype = "image/jpg"; break; default: $ctype = "application/force-download"; } header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); // required for certain browsers header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=\"" . basename($file_path) . "\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize); ob_clean(); flush(); readfile($file_path);` 

The code I saw on php.net

 // If it a large file, readfile might not be able to do it in one go, so: $chunksize = 1 * (1024 * 1024); // how many bytes per chunk if ($size > $chunksize) { $handle = fopen($realpath, 'rb'); $buffer = ''; while (!feof($handle)) { $buffer = fread($handle, $chunksize); echo $buffer; ob_flush(); flush(); } fclose($handle); } else { readfile($realpath); } 
+7
source share
1 answer

Use readfile() . It will transfer the file in small fragments and process all background work in order to maintain minimal memory usage.

+3
source

All Articles