我正在尝试使用 JWPlayer 在我的网站上播放视频。但是我无法从 php 动态获取视频,因为我收到以下错误:
加载媒体时出错:无法播放文件
我目前的代码是:
<?php
include('connection.php');//connect to db
$id = $_GET['id'];//get video id from param
$video = mysql_query("SELECT * FROM video_table WHERE id = '$id'");//video row from db
$data = mysql_fetch_assoc($video);
$ext = pathinfo($data['video_name'], PATHINFO_EXTENSION);
$file_name = $id . "." . $ext;
echo $file_name;
?>
<div id="container1"></div>
<script type="text/javascript">
jwplayer('container1').setup({
'id': 'container1',
'type': '<?php echo $ext ?>',
'wmode': 'transparent',
'flashplayer': 'jwplayer/jwplayer.flash.swf',
'file': 'video.php',
'provider': 'video',
'width': '480',
'height': '320',
});
</script>
</div>
视频.php
<?php
include('connection.php');
$id = $_GET['id'];
$video = mysql_query("SELECT * FROM video_table WHERE id = '$id'");
$data = mysql_fetch_assoc($video);
$ext = pathinfo($data['video_name'], PATHINFO_EXTENSION);
$type = pathinfo($data['type'], PATHINFO_EXTENSION);
$file_name = $id . "." . $ext;//set the file name as saved in upload directory e.g: 1.mp4
header("pragma : no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Content-Type: $type");
header("Content-Location: upload/$file_name");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("upload/$file_name"));
readfile("upload/$file_name");
?>
但是,如果我在这里更改了绝对名称,(upload/1.mp4) instead of (upload/$file_name)
它就可以工作并提供视频。如何从参数动态获取视频?