mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-19 06:28:01 +00:00
serve mp4s directly
This commit is contained in:
@@ -92,57 +92,12 @@ class VideoController implements ContentController
|
||||
//via gist: https://gist.github.com/codler/3906826
|
||||
function serveMP4($path,$hash)
|
||||
{
|
||||
if ($fp = fopen($path, "rb"))
|
||||
{
|
||||
$size = filesize($path);
|
||||
$length = $size;
|
||||
$start = 0;
|
||||
$end = $size - 1;
|
||||
header('Content-type: video/mp4');
|
||||
header ("Last-Modified: ".gmdate('D, d M Y H:i:s ', filemtime($path)) . 'GMT');
|
||||
header ("ETag: ".sha1_file($path));
|
||||
header('Cache-control: public, max-age=31536000');
|
||||
header("Accept-Ranges: 0-$length");
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
$c_start = $start;
|
||||
$c_end = $end;
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
if (strpos($range, ',') !== false) {
|
||||
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
||||
header("Content-Range: bytes $start-$end/$size");
|
||||
exit;
|
||||
}
|
||||
if ($range == '-') {
|
||||
$c_start = $size - substr($range, 1);
|
||||
} else {
|
||||
$range = explode('-', $range);
|
||||
$c_start = $range[0];
|
||||
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
|
||||
}
|
||||
$c_end = ($c_end > $end) ? $end : $c_end;
|
||||
if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
|
||||
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
||||
header("Content-Range: bytes $start-$end/$size");
|
||||
exit;
|
||||
}
|
||||
$start = $c_start;
|
||||
$end = $c_end;
|
||||
$length = $end - $start + 1;
|
||||
fseek($fp, $start);
|
||||
header('HTTP/1.1 206 Partial Content');
|
||||
}
|
||||
header("Content-Range: bytes $start-$end/$size");
|
||||
header("Content-Length: ".$length);
|
||||
$buffer = 1024 * 8;
|
||||
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
|
||||
if ($p + $buffer > $end) {
|
||||
$buffer = $end - $p + 1;
|
||||
}
|
||||
set_time_limit(0);
|
||||
echo fread($fp, $buffer);
|
||||
flush();
|
||||
}
|
||||
fclose($fp);
|
||||
header('X-Accel-Redirect: '.str_replace(getDataDir().DS,'',$path));
|
||||
exit();
|
||||
} else die('file not found');
|
||||
}
|
||||
|
||||
function isProperMP4($filename)
|
||||
|
||||
Reference in New Issue
Block a user