我正在使用一种技术来防止用户下载带有临时链接的视频,但是问题是当我在源代码中提供链接时,视频会加载但无法滚动(例如:从0:00到1:25 ),这就是我创建视频元素并附加链接的索引页的代码
<?php
include_once('dbconfig.php');
function mysql_date($time, $opt = ''){
switch($opt){
case 0:
//Return datetime
return date('Y-m-d H:i:s', $time);
break;
default:
//Return default date
return date('Y-m-d', $time);
}
}
function generate_link($filename){
$id = uniqid();
$timestamp = mysql_date(time(), 0);
$query = mysql_query('INSERT INTO `temporary_links`(`filename`, `token`,
`timestamp`) VALUES ("' . $filename. '", "' . $id. '", "' . $timestamp .
'")');
return 'stream.php?i=' . $id;
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Stream</title>
</head>
<body>
<video width="600" height="300" controls>
<source src="<?php echo generate_link('music.mp4'); ?>"
type="video/mp4">
</video>
<video width="600" height="300" controls preload="none">
<source src="music.mp4" type="video/mp4">
</video>
</body>
</html>
然后这是读取视频文件的文件
<?php
include_once('dbconfig.php');
if(isset($_GET['i']) && !empty($_GET['i'])){
$id = $_GET['i'];
$filename_query = mysql_query('SELECT `filename`, `token` FROM `temporary_links` WHERE `token`="' . $id . '"');
if(mysql_num_rows($filename_query) > 0){
$filename = mysql_fetch_assoc($filename_query);
$filename = $filename['filename'];
destroy_link($id);
if(file_exists($filename)){
ob_get_clean();
header("Content-Type: video/mp4");
header("Cache-Control: no-cache");
header("Content-Length: " . filesize($filename));
readfile($filename);
ob_flush();
flush();
exit;
}
}else{
header("HTTP/1.0 404 Not Found");
exit;
}
}
function destroy_link($id){
return mysql_query('DELETE FROM `temporary_links` WHERE `token`="' . $id . '"');
}
?>
视频再次完美加载,但不能从(0:00到1:20)跳过。预先感谢您的帮助。