Serving local windows media files via PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone,

I am working on a project where I have .wmv files stored outside of
the server's www root, and want to serve them via a custom web
interface. It's all on windows, and is only intended to work locally
on the physical machine it runs on (don't ask, the customer is

Right now I have a working prototype in which I use a PHP script
(called movie.php) to serve the target file. In the HTML page, I have
an OBJECT tag that refers to the script, like so:

<OBJECT ID="MediaPlayer" WIDTH="512" HEIGHT="384"
STANDBY="Loading Windows Media Player components..."
<PARAM NAME="FileName" VALUE="movie.php?fileID=12345">
<PARAM name="ShowControls" VALUE="true">
<param name="ShowStatusBar" value="true">
<PARAM name="ShowDisplay" VALUE="true">
<PARAM name="autostart" VALUE="true">
<EMBED TYPE="application/x-mplayer2"

The movie.php script itself is pretty simple too (stripped down to the


    $timeout = 60 * 60 * 24 * 2;
    header( 'Cache-Control', 'private, max-age=' . $timeout . '' );
    header( 'Pragma', 'private, max-age=' . $timeout . '' );
    header( 'Expires', gmdate( 'D, d M Y H:i:s', time() + $timeout ) . '
GMT' );
    header( 'Content-Type:video/x-ms-wmv' );
    readfile( $file );


This gives me a working player, but the big downside is the player
won't let me skip the clips :(

The seek bar does not respond to any requests to skip ahead, and
pausing the video resets it to the start. Any idea on how I can fix
this so I can skip ahead as much as I wish?

Thanks a lot!

Re: Serving local windows media files via PHP


Seeking usually involves a partial GET request ( /

You could handle the range request in your script and send the byte
range specified in $_SERVER['HTTP_RANGE'] along with appropriate
headers. Example here:

Alternatively, you can let Apache send the requested part directly by
using mod_rewrite and a map containing authorized sessions. Good
example here:

The first is more flexible in terms of authorization and logging etc.
The second method would have slightly better performance, but I
wouldn't worry about it unless you're handling very high loads.


John Peters

Quoted text here. Click to load it

Re: Serving local windows media files via PHP

Quoted text here. Click to load it

Don't use wmv.

In addition to solving the player problems, you'll reach a wider
audience and prevent leeching by using mpeg and Flash - see


Site Timeline