|
Posted by Stefan Rybacki on 07/01/05 23:46
Hilarion wrote:
>> [...] it is also possible to provide a resume function by the download
>> script.
>
>
> I assumed that it's possible but I suppose it's quite hard to code.
> If you know some PHP code that does it, then please post it here (i've been
> looking for something like that for long time). If you know any way how
> to use Apache abilities from PHP to do it, then it's even better.
>
>
> Hilarion
>
>
>
Its all about headers:
For example sending this to a client:
HTTP/1.1 200 OK
Connection: close
Date: Tue, 19 Oct 2004 15:11:23 GMT
Accept-Ranges: bytes
Last-Modified: Sun, 26 Sep 2004 15:52:45 GMT
ETag: "47febb2cfd76c41:2062"
Cache-Control: private
Content-Type: application/x-zip-compressed
Content-Length: 2844011
let the client know that resuming is possible, and for example the
client sends the following back:
GET http://192.168.100.100/download.zip HTTP/1.0
Range: bytes=822603-
Unless-Modified-Since: Sun, 26 Sep 2004 15:52:45 GMT
If-Range: "47febb2cfd76c41:2062"
Then you send something like this:
HTTP/1.1 206 Partial Content
Content-Range: bytes 822603-2844010/2844011
Accept-Ranges: bytes
Last-Modified: Sun, 26 Sep 2004 15:52:45 GMT
ETag: "47febb2cfd76c41:2062"
Cache-Control: private
Content-Type: application/x-zip-compressed
Content-Length: 2021408
As you mentioned its kinda wasteful to keep track of what is sent to the
script but it is not that difficult.
As well on the fpassthru function page in the php manual:
"
nexz2004 at yahoo dot com
21-May-2004 09:30
also it is possible to make your php script resume downloads, to do this
you need to check $_SERVER['HTTP_RANGE'] which may contain something
like this
"bytes=10-" - resume from position 10, and to end of file
when sending response it is also needed to send with headers
Accept-Ranges: bytes
Content-Length: {filesize}
Content-Range: bytes 10-{filesize-1}/{ffilesize}
hope its usefull
"
On this address you will find a complete example of such a code:
http://de2.php.net/fread
Regards
Stefan
[Back to original message]
|