note 107482 added to function.fread

From: Date: Sun, 12 Feb 2012 22:26:21 +0000
Subject: note 107482 added to function.fread
Groups: php.notes 
Request: Send a blank email to php-notes+get-186090@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 85.180.111.252 ---- Manual Page -- http://www.php.net/manual/en/function.fread.php Edit -- https://master.php.net/note/edit/107482 Del: integrated -- https://master.php.net/note/delete/107482/integrated Del: useless -- https://master.php.net/note/delete/107482/useless Del: bad code -- https://master.php.net/note/delete/107482/bad+code Del: spam -- https://master.php.net/note/delete/107482/spam Del: non-english -- https://master.php.net/note/delete/107482/non-english Del: in docs -- https://master.php.net/note/delete/107482/in+docs Del: other reasons-- https://master.php.net/note/delete/107482 Reject -- https://master.php.net/note/reject/107482 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186090) next »