We are using a PHP scripting for tunnelling file downloads, since we don't want to expose the absolute path of downloadable file:
header("Content-Type: $ctype");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=\"$fileName\"");
readfile($file);
Unfortunately we noticed that downloads passed through this script can't be resumed by the end user.
Is there any way to support resumable downloads with such a PHP-based solution?
Best Answer
The first thing you need to do is to send the
Accept-Ranges: bytes
header in all responses, to tell the client that you support partial content. Then, if request with aRange: bytes=x-y
header is received (withx
andy
being numbers) you parse the range the client is requesting, open the file as usual, seekx
bytes ahead and send the nexty
-x
bytes. Also set the response toHTTP/1.0 206 Partial Content
.Without having tested anything, this could work, more or less:
I may have missed something obvious, and I have most definitely ignored some potential sources of errors, but it should be a start.
There's a description of partial content here and I found some info on partial content on the documentation page for fread.