Streaming video / mp 4 with php

I am having a problem with streaming an mp4 file via php. File downloads hang at 1MB. You can see it here: NGHVm.png I've tried a lot of headers and read a lot of streams, but many haven't solved or helped me like this one: MP4 plays when accessed directly, but not when read through PHP, on iOS . Any help please?

There is my code:

<?
$root=getenv("DOCUMENT_ROOT");
$file = "$root/".$_GET['get'];
header("Content-Type: video/mp4");
//header("Content-Type: application/octet-stream"); // downloads the file

$start=0;
$size = filesize($file);
$length = $size;
$end = $size - 1;

//header('HTTP/1.1 206 Partial Content');
header("Accept-Ranges: $start-$end");
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: $length");


$data = fopen("$file", "r");
fseek($data, $start);

$bytesleft = $size-$start + 1;
$buffer = 1024 * 256; // 256kb
while(!feof($data)){
    if($bytesleft > $buffer){
        echo fread($data, $buffer);
        flush();
    }else{
        echo fread($data, $bytesleft);
        flush();
    }
    //sleep(1);  // Speedlimit = one buffer per second
}


fclose($data);
exit;
?>

      

Thank you in advance

+3


source to share


1 answer


Nevermind. I downloaded the file from the server and compared it to the original stored on the server in hexadecimal format. The loaded one had one more byte at start: 0A and that was the problem. Everything is working now.



0


source







All Articles