我有 HTML 视频此标签用于视频播放.................
<video id="video-help" width="530" controls>
<source id="videoPath" src="whatever.php?p=123" type="video/mp4">
</video>
我有这个随便.php文件代码..
<?php
if($_GET['p']!='123'){
die('Not Found');
}
$file = "https://drive.google.com/uc?export=preview&id=1ym-pJX8yCMs6Sz1z-bwHuD4MIBwlOmAT";
if(!file_exists($file)) return;
$fp = @fopen($file, 'rb');
$size = filesize($file); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
header('Content-type: video/mp4');
header("Accept-Ranges: 0-$length");
header("Accept-Ranges: bytes");
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);
ob_flush();
}
fclose($fp);
exit();
?>
此 php 代码不适用于视频网址,请解决我的这个问题.........................
我从早上起就一直在尝试做这个,但我做不到,请解决这个问题
当我们放置主机的视频链接时,此代码有效,但我必须从其他网络链接执行此操作
这是你的问题:
$file = "https://drive.google.com/uc?export=preview&id=1ym-pJX8yCMs6Sz1z-bwHuD4MIBwlOmAT";
if(!file_exists($file)) return;
file_exists
仅检查“本地”文件,无法检查 URL 中的文件。看this https://stackoverflow.com/questions/10444059/file-exists-returns-false-for-remote-urlstackoverflow线程如何处理呢!
还值得一提的是:
为了fopen
要使用 url,请确保allow_url_fopen
在 php.ini 中设置为 true (默认情况下应该为 true)。来自官方文档 https://www.php.net/manual/de/filesystem.configuration.php#ini.allow-url-fopen:
allow_url_fopen bool:此选项启用 URL 感知的 fopen 包装器
允许访问 URL 对象(如文件)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)