How to force download of big files without using too much memory? How to force download of big files without using too much memory? codeigniter codeigniter

How to force download of big files without using too much memory?


There are some ideas over in this thread. I don't know if the readfile() method will save memory, but it sounds promising.


You're sending the contents ($data) of this file via PHP?

If so, each Apache process handling this will end up growing to the size of this file, as that data will be cached.

Your ONLY solution is to not send file contents/data via PHP and simply redirect the user to a download URL on the filesystem.

Use a generated and unique symlink, or a hidden location.


I searched too many scripts and advises and nothing worked for my 400MB PDF file. I ended up using mod_rewrite and here's the solution it works great https://unix.stackexchange.com/questions/88874/control-apache-referrer-to-restrict-downloads-in-htaccess-file The code only allows download from a referrer you specifies and forbids direct download

 RewriteEngine OnRewriteCond %{HTTP_REFERER} !^http://yourdomain.com/.* [NC]RewriteRule .* - [F]