Useful PHP force-download script

It seems there are a million force-download scripts out there for PHP.  Most people will agree that mod_xsendfile is the way to go, but if your web host won't support it (for example, it may conflict with NFS), check out http://www.richnetapps.com/php-download-script-with-resume-option/

P.S. If you use the second script and need to download Mac dmg files, I recommend you first wrap the dmg file into a zip file and have users download the zip file instead of the dmg file directly since the force download script may add a small amount of of binary data to large files and alter the md5 fingerprint.  

Update: this turned out to be an issue with Drupal interjecting error messages into the binary download stream.  Make sure to turn OFF error messaging if using Drupal (see https://drupal.org/node/1036982)

Update #2: the in-memory chunking method described above is still prone to failed downloads, especially on large multi-gigabyte files, when using a slow Internet connection or when there is heavy network congestion.  The best approach is a variation of http://serverfault.com/a/150542 (I recommend using the at command to delete the symbolic link a couple minutes after creating it rather than a cron job that deletes it a day later).  

Pseudo-code:

Comments

Popular Posts