假如資源地址 : http://xxx.com/videoData/xxx.mp4 即可實現播放;
detail.html模板內容
<video controls="controls" autoplay="autoplay">
<source type="video/ogg" src="xxx.com/goVideo.php?video=1" /><!--這樣的地址他們就醉了吧,真實地主保護住了 而且每次進入詳情頁播放完了,重新進入detail鏈接方法中,才能播放 -->
Your browser does not support the video tag.
</video>
detail.php控制層內容
// 先進入詳情頁
publicfunction detail(){
$_SESSION['token'] = md5("xxx"); //做一個token 用於失效方案
//進入到詳情頁
}
goVideo.php代碼如下
/**
+----------------------------------------------------------
* 生成html video 播放地址
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function goVideo()
{
$vid = (int)$_GET['videoId']; //數據庫存放的資源id
$data = $this->getInfo($vid); //通過vid 獲取 數據庫存放的真實資源地址
if($_SESSION["token"]){
unset($_SESSION["token"]); //刪除token,保證每次只能播放一次
//頁面直接輸出視頻
$filePath=$data['URL'];
ini_set('memory_limit', '512M');
header("Pragma: public");
header("Expires: 0");
header("Content-Type: application/octet-stream"); //文件mime類型
//header("Content-Disposition: attachment; filename=video11.mp4;" ); //文件名$filename
//header("Content-Length: 83995"); //文件大小$fsize
ob_clean();
flush();
//ob_end_clean();
@readfile($filePath);
}
}
————————————————
版權聲明:本文為CSDN博主「qq_41211900」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_41211900/article/details/82427860