I am working on a project that downloads large zip files from server, for small files the script works well and downlaod files successfully, but for larger files like currently we are trying to download a 922MB file it gives us this message (in firefox) and doesn’t download any thing.
GoDaddy has asked for the following in order to install mod_xsend on our server:
“Written acknowledgment/agreement of the following potential issues, including, but not limited to:
- Functionality differences between the old and new software.
- Compatibility issues of installed services/applications/dependencies.
- Application version differences (PHP, MySQL, etc.).”
Is their an actual reason why you are using PHP to send the file? Why don’t you have the server do this work like it was meant to do it? Ie., have the server deliver the file like it does your images. Large files like this 900 MB file is just going to kill PHPs memory limit.
Thats probably what is going on - it’s probably causing an error and thus the file stream won’t be output to the browser.
@op: You need to rethink the logic here. What you need to do is hide the files and output a header to them when you receive a valid token from your user (the token being supplied in the url).
With regards to the file itself, you need to read from the file in a loop and write them out to the client - not use readfile() which is only good for smaller files. For larger files you need to read a few KB and print that in a loop. This means that you only ever have a few KB of the file in the memory at any time.
OF course by doing that, you then need to support pause and resume so hit google for a function called: dl_file_resumable
That function will also show you how to read from a file and print it out a few KB at a time.
Yes but if the downloads are being paid for then as the op says you need to protect your income otherwise people will just pass the url around for a free download. THAT is why php is very useful for download situations like this.
You generate a random string for the URL so that no one can guess it - and it is not a folder name although it looks like that. Then use PHP to add this URL to a rewrite rule in your .htaccess file so that the file is accessible for download using this particular URL. In this way you skip PHP entirely in the download process and your server is serving the file directly.
Just remember to run a script every X minutes which will remove obsolete URLs from your .htaccess so that they expire. You can use some database to keep track of them.
I have seen some music download sites use this technique. I don’t know what kind of scripting they use but they generate unique download URLs that are accessible for 24 hours. This has the advantage that people can use their favourite download managers to get the file, which can be important for such huge downloads.