LendKey

Saturday, December 1, 2007

Implement resumable file download by PHP

I had a requirement to implement a file downloading service with Apache + PHP.
The files are all uploaded by another tool. All uploaded files are renamed to UUID, and a UUID.info file is attached to store corresponding information of the original file.

Now at downloaded side, I need to:
1. verify UUID info before download
2. still able to download the file into the original file name instead of a user-in-friendly UUID.
3. Support browser and download manager, such as FlashGet

Without PHP code the 1 and 2 could not be accomplished.
But to support 3, PHP does not have any built-in support. Especially when considering downloading large files from server, PHP normally does not work well.

Luckily, I found a PHP class from:
http://www.phpclasses.org/browse/package/2221.html

Big thanks to the author, I was able to implement all I needed in less than 30 lines of my code :)

Hopefully, my finding can be helpful to you.

Li

No comments: