I am trying to use JWPlayer to play videos on my website. But I cannot get the video served from php dynamically as I'm getting the following error:
Error loading media: File could not be played
My current code is:
<?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>
video.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");
?>
However, if I changed the absolute name here (upload/1.mp4) instead of (upload/$file_name)
it works and video is provided. How can I get the video dynamically from parameter?