我想避免下载我的视频。所以我使用这个脚本是为了避免用户下载视频并且它有效!
但我无法随时播放该视频。这仅适用于 Google Chrome。
这就是我使用以下脚本的原因:
index.php:
ini_set('session.use_cookies',1);
session_start();
$vid=uniqid();
$_SESSION[$vid]='myVideo.mp4';
echo '<video autoplay="autoplay">'
.'<source src="video.php?video='.$vid.' type="video/mp4">'
.'</video>';
视频.php:
ini_set('session.use_cookies',1);
session_start();
$file='myhiddenvideos/'.$_SESSION[$_GET['video']];
$_SESSION=array();
$params = session_get_cookie_params();
setcookie(session_name(),'', time()-42000,$params["path"],$params["domain"],
$params["secure"], $params["httponly"]);
if(!file_exists($file) or $file==='' or !is_readable($file)){
header('HTTP/1.1 404 File not found',true);
exit;
}
readfile($file);
exit;
现在这段代码的问题是,我无法随时从栏的任何位置查找或播放我的视频!
最佳答案
这是因为您的视频文件被作为 text/html
文件提供,因此浏览器无法理解如何处理该文件。 (嗯,Firefox 可以理解,而 Chrome 则不能。)
您必须向浏览器指示 MIME type通过 Content-Type
header 获取视频.
header('Content-Type: video/mp4');
readfile($file);
exit;
关于javascript - 任何视频播放器都无法使用临时视频源文件寻找视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28367003/