As usual, it never works for me ...
I am trying to transfer a video and I am doing very well with the code below:
function send_back_video($video_path)
{
ob_clean();
$mime = "application/octet-stream";
$size = filesize($video_path);
header('Content-type: ' . $mime);
if(isset($_SERVER['HTTP_RANGE']))
{
$ranges = array_map(
'intval',
explode(
'-',
substr($_SERVER['HTTP_RANGE'], 6)
)
);
if(!$ranges[1]){
$ranges[1] = $size - 1;
}
header('HTTP/1.1 206 Partial Content');
header('Accept-Ranges: bytes');
header('Content-Length: ' . ($ranges[1] - $ranges[0]));
header(
sprintf(
'Content-Range: bytes %d-%d/%d',
$ranges[0],
$ranges[1],
$size
)
);
$f = fopen($video_path, 'rb');
$chunkSize = 8192;
fseek($f, $ranges[0]);
while(true)
{
if(ftell($f) >= $ranges[1])
{
break;
}
echo fread($f, $chunkSize);
@ob_flush();
flush();
}
}
else {
header('Content-Length: ' . $size);
@readfile($file);
@ob_flush();
flush();
}
}
"So, if that works, what do you need?" - you ask.
As I said, the code does a very good job, BUT there is 1 problem.
If I start playing the video, php will send header('HTTP/1.1 206 Partial Content')and this (video) request will remain open until EOF, which means I FORCED to download the entire video, even if I don’t want to (say, I click on the next video).
My JS removes the video tags (this should be an ABORT request) and creates a new video tag with a new link. Part of ABORT does not occur.
Here you can see the GET example:

- 1st - get the initial video
- 2nd - play button pressed
- 3rd - - DOM .
, , .
, youtube GET. , GET "", "" . , , .
P.S.
, - , , .
P.P.S.
.