note 107482 deleted from function.fread by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 21:05:50 +0000 |
| Subject: | note 107482 deleted from function.fread by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187853@lists.php.net to get a copy of this message | ||
Note Submitter: florian dot hoech at gmx dot de
----
The below download example by andrej dot frelih at gmail dot com is faulty. It doesn't
calculate $data_size correctly for partial content, and the Content-Range header is also incorrect.
The reason is that the range needs to be specified as byte offsets, so the second number in e.g.
'bytes=500-9999' is NOT a length. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
and http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
This is the correct way to do it:
<?php
if ($partial_content) $data_size = intval($range[1]) - intval($range[0]) + 1;
?>
<?php
if ($partial_content) header('Content-Range: bytes ' . $offset . '-' .
($offset + $length - 1) . '/' . $file_size);
?>
The example has other shortcomings (not all forms of the Range header are supported), but I
won't go into this in detail.