I\'m writing a web app that serves H.264 encoded MP4 video. In Chrome and Safari, it does this via an HTML5 video tag.
In order to control access to these videos, th
Maybe. Try adding also the content length header:
header('Content-length: '.filesize($filename));
If this still doesn't work, check for any output before readfile
(echo
's or whitespace before ). Check also that you don't have whitespace after
?>
or simply omit ?>
(it's not mandatory if you have nothing after).
As Bruno mentioned, to support streaming, you also need to obey the Range
header. Here's a simplified example that respects only the left bound:
if (empty($_SERVER["HTTP_RANGE"])) {
//do your current stuff...
}
else { //violes rfc2616, which requires ignoring the header if it's invalid
preg_match("/^bytes=(\d+)-/i",$_SERVER["HTTP_RANGE"], $matches);
$offset = (int) $matches[1];
if ($offset < $filesize && $offset >= 0) {
if (@fseek($fp, $offset, SEEK_SET) != 0)
die("err");
header("HTTP/1.1 206 Partial Content");
header("Content-Range: bytes $offset-".($filesize - 1)."/$filesize");
}
else {
header("HTTP/1.1 416 Requested Range Not Satisfiable");
die();
}
//fread in loop here
}