通过php传输视频Url
我创建了一个简单的php代码,将流一个视频文件传送到php服务器,然后传送到浏览器 视频播放正常,但我无法滚动视频 如何正确地传递从php到curl的范围。通过php传输视频Url,php,video,video-streaming,Php,Video,Video Streaming,我创建了一个简单的php代码,将流一个视频文件传送到php服务器,然后传送到浏览器 视频播放正常,但我无法滚动视频 如何正确地传递从php到curl的范围。 <?php header("Content-Type: video/mp4"); header('Accept-Ranges: bytes'); $downloadLink = "https://vjs.zencdn.net/v/oceans.mp4"; $size = '23014356'; // F
<?php
header("Content-Type: video/mp4");
header('Accept-Ranges: bytes');
$downloadLink = "https://vjs.zencdn.net/v/oceans.mp4";
$size = '23014356'; // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
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);
$opts = array(
'http'=>array(
'method'=>"GET",
"cache-control: no-cache",
"Content-Range: bytes $start-$end/$size"
)
);
$context = stream_context_create($opts);
$fp = fopen("$downloadLink", 'r', false, $context);
fpassthru($fp);
fclose($fp);
记住它不是本地文件。这是一个视频url。只是一个友好的提示,你可能想在这个页面上阅读:所以你可以始终确保你的问题很容易回答并且尽可能清楚。请确保包括您为解决问题所做的任何努力,以及在尝试这些修复时发生的情况。另外,不要忘记查看您的代码和任何错误消息!记住它不是本地文件。这是一个视频url。只是一个友好的提示,你可能想在这个页面上阅读:所以你可以始终确保你的问题很容易回答并且尽可能清楚。请确保包括您为解决问题所做的任何努力,以及在尝试这些修复时发生的情况。另外,不要忘记查看您的代码和任何错误消息!