ThomThom's Website

PHP Resumable Download Server

22 Sep 07 - 13:23

I wanted to add a download section to my site, but at the same time keep statistics of the files downloaded. So made a little PHP script to act as a download server.

This little script became a little larger when I added support for partial file downloads. I noticed that many comments in the PHP manual and other sources described the method wrong. For instance, many of them announced to accept multiple byte ranges while that was not the fact. And they also tended to not handle the requested byte range according to the HTTP 1.1 specifications.

Now, I'm never pretending this is a complete implementation or free for issues. But it should work very well and I've tried to make it behave to the specifications.


  • Serves files from a file repository.
  • Makes sure no files outside the repository is served.
  • Lists files if a directory is requested.
  • Supports partial file request allowing users to pause or accelerate downloads.
  • Logging function to keep statistic over the file downloads. (Needs configuring to work.)

Live Example

Known Issues

  • Files larger than 2GB might give unexpected results on platforms that use 32-bit integers. This is because it might affect the calculation of filesizes.


21 June 2011: I have uploaded the project at BitBucket. It is the recommended way to obtain the project. Now you can send back your patches and improvements.


Installation instructions is in the readme.txt file.

Download latest version from the BitBucket repository.


  • On 20.05.08 21:12 GMT Shamus said:

    Hi. There is no settings.ini file in the package, as referenced in step 1 of your readme.txt file. Please advise how to access this file.
  • On 27.05.08 13:08 GMT Thomas Thomassen said:

    My apologies Shamus. The reference to "settings.ini" in the readme.txt is suppose to be "server.ini".
    Thanks for pointing that out.
  • On 12.02.09 04:34 GMT Thangaraj said:

    Great script!

    Worked well for me. I used the partial download feature into one of our file serving scripts.

    Thank you :)
  • On 12.02.09 11:26 GMT Thangaraj said:

    Great script!

    Worked well for me. I used the partial download feature into one of our file serving scripts.

    Thank you :)
  • On 13.03.09 02:21 GMT shabi said:

    i want to find php server so i get it from this web.
  • On 19.06.09 06:53 GMT Stuffs said:

    line: 152
    // workaround for IE filename bug with multiple periods / multiple dots in filename
    // that adds square brackets to filename - eg. becomes setup[1].abc.exe
    $iefilename = preg_replace('/./', '%2e', $basename, substr_count($basename, '.') - 1);


    $iefilename =
    should be read
    $basename =

    Else your IE fix is not going to be passed once it it outside that section that fixes it.
  • On 22.06.09 16:30 GMT Thomas Thomassen said:

    Thanks Stuffs!
  • On 02.10.09 16:20 GMT Neil said:

    Just FYI -- if you attempt to do byte-range requests with this download server over HTTPS/SSL with a self-signed certificate using the iPhone, it will fail mysteriously with only a generic "This movie cannot be played" error on the iPhone. This took me a week to finally figure out....
  • On 03.10.09 13:25 GMT Thomas Thomassen said:

    hm. I've not dealt with HTTPS/SSL. Not sure why that doesn't work. You emphasize self-signed certificate, does it work with any other types?
  • On 06.10.09 09:21 GMT Chris Gibbs said:

    Hi Thomas, I hope you don't mind, but I've filed an improvement to the WordPress MU project that will use your logic to support byte-range downloads. You can see it here: []

    Also, I would like to say thank you for keeping your code open, it has saved me a lot of time and work!
  • On 14.10.09 12:41 GMT Thomas Thomassen said:

    Not a problem Chris. Glad it's of help. Thanks for posting back a link to where it's used.
  • On 10.11.12 21:24 GMT Nguyen Thai Ha said:

    That's Greate. Thanhks Thomas !
Comments are closed due to spam. Thank you spammers, well done!