Closed Ragazzo closed 11 years ago
What is your use case exactly?
The same one, jPlayer (or other js) can ask for a part of the file, so i need to handle this one situation, also chrome sends this header and needs it back in correct form. I was mentioned this ench. early in some issue about CHttpRequest, so i just decided to ask if it needed. My opinion yes, because of some browsers also can download file by parts, or am i wrong about it?
Ah, right. Can be useful. What API do you suggest for it?
Hm, API... i was suggesting just to modify CHttpRequest::sendFile() method to check if there is a $_SERVER['HTTP_RANGE'] and serve it correctly, smth like this:
//code from sendFile above
$fullContentLength = (function_exists('mb_strlen') ? mb_strlen($content,'8bit') : strlen($content));
if (isset($_SERVER['HTTP_RANGE']))
{
$range = $_SERVER['HTTP_RANGE'];
$range = str_replace('bytes=', '', $range);
list($range, $end) = explode('-', $range);
if (!empty($range))
$content = substr($content,$range);
}
else
$range = 0;
if ($range != 0)
header($_SERVER['SERVER_PROTOCOL'].' 206 Partial Content');
else
header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
//.... sendFile headers
header('Accept-Ranges: bytes');
header('Content-Length: '.(function_exists('mb_strlen') ? mb_strlen($content,'8bit') : strlen($content)));
header('Content-Range: bytes '.$range.'-'.($fullContentLength).'/'.$fullContentLength);
If it must be like API i think can do it if you will say what kind of API.
No, I think it's good as is. If client is sending range headers than sendfile should definitely respond accordingly.
So, need a PR?
Yes.
Ok, will work on it. Thanks for your replies.
I think need to be implemented to hold range-requests, i mean $_SERVER['HTTP_RANGE'], i've allready have one working solution, so if needed can make a PR, good enhancement i think. Need opinions of fw devs.