Serving Up a file (mp4, flv, etc.) using PHP
I hope someone can offer some assistance.
I'm trying to serve up a video file (mp4 or flv) from a PHP script. Please not that I do NOT necessarily want to "stream" the file (using pseudo-streaming, etc.)
I've researched the posts in this forum for the last three days and have tried several solutions to no avail. I've made a few notes below and hopefully have described what I'm looking for with enough detail. Please feel free to use the URLs below for testing.
Here's the test scenario:
- We have a "media server" located at http://media1.waywardmediagroup.com
- There is an mp4 file on there. You can access it with http://media1.waywardmediagroup.com/mediatest.mp4
- Using that URL, It can be access from a browser, QuickTime Player, VLC, etc.
- Also, when I use that URL in the JWPlayer (see below), it works just fine
- NOTE: The JWPlayer and the Media are on separate servers
*** THIS WORKS ***
<script type="text/javascript" src="/tools/jwplayer/jwplayer.js"></script>
<div id="mediaspace">Loading the player ...</div>
<script type="text/javascript">
jwplayer("mediaspace").setup({
height: 263,
width: 478,
file: 'http://media1.waywardmediagroup.com/mediatest.mp4',
image: "/tools/preview.jpg",
provider: "video",
skin: "tools/jwskins/fs33aqua/fs33aqua.xml",
players: [
{ type: "flash", src: "/tools/jwplayer/player.swf" },
{ type: "html5" }
]
});
</script>
*** THIS DOES NOT WORK ***
<script type="text/javascript" src="/tools/jwplayer/jwplayer.js"></script>
<div id="mediaspace">Loading the player ...</div>
<script type="text/javascript">
jwplayer("mediaspace").setup({
height: 263,
width: 478,
file: 'http://media1.waywardmediagroup.com/media.php?file=movie.mp4',
image: "/tools/preview.jpg",
provider: "video",
skin: "tools/jwskins/fs33aqua/fs33aqua.xml",
players: [
{ type: "flash", src: "/tools/jwplayer/player.swf" },
{ type: "html5" }
]
});
</script>
NOTES:
- the media.php file is a simple PHP script which serves the file
- "?file=movie.mp4" is a dummy parameter that is being ignored by the php script (for now). However, the JWPlayer sees the ".mp4" and (hopefully) thinks everything is ok
- The HHTP headers returned by media.php are the same as when the file is accessed through it's URL (http://media1.waywardmediagroup.com/mediatest.mp4)
- Please note that I am NOT attempting to do pseudo-streaming hereI just want to deliver the contents of the file in the same manner as when it is accessed directly
- Also, you can play the video in quicktime and vlc using the php url (http://media1.waywardmediagroup.com/media.php)
*** THE PHP SCRIPT (media.php) ***
<?php
// Hard-Coded for the test
$file = 'mediatest.mp4';
if (file_exists($file))
{
header('Last-Modified: Thu, 23 Sep 2010 02:00:02 GMT');
header('ETag: "c0101-309f8-490e39ebcec80"');
header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($file));
header('Connection: close');
header('Content-Type: video/mp4');
header('X-Pad: avoid browser bug');
ob_clean();
flush();
readfile($file);
exit;
}
?>
*** HTTP Headers from accessing the file directly (http://media1.waywardmediagroup.com/mediatest.mp4) ***
Status: HTTP/1.1 200 OK
Date: Fri, 04 Feb 2011 17:51:36 GMT
Server: Apache/2.2.15 (Fedora)
Last-Modified: Thu, 23 Sep 2010 02:00:02 GMT
ETag: "c0101-309f8-490e39ebcec80"
Accept-Ranges: bytes
Content-Length: 199160
Connection: close
Content-Type: video/mp4
X-Pad: avoid browser bug
*** HTTP Headers from accessing the file through the php script (http://media1.waywardmediagroup.com/media.php) ***
Status: HTTP/1.1 200 OK
Date: Fri, 04 Feb 2011 17:53:46 GMT
Server: Apache/2.2.15 (Fedora)
X-Powered-By: PHP/5.3.3
Last-Modified: Thu, 23 Sep 2010 02:00:02 GMT
ETag: "c0101-309f8-490e39ebcec80"
Accept-Ranges: bytes
Content-Length: 199160
Connection: close
X-Pad: avoid browser bug
Content-Type: video/mp4