PHP, Apache – how to call php script if a .mp4 file has been requested

  apache2.4, php, windows

I have a service that downloads files in a specfic format from a site, remote.com/file.wav and must translate them on the fly exposing them like local.it/file.ogg.

Doing so when someone goes to local.com/file.mp4 the site connects to remote.com/file.raw downloads the file, convert it calling a windows program myconv.exe -i file.raw file.mp4 and serves file.ogg.

Now I have the script for the download:

$file_to_download= str_replace('/','',$_SERVER['SCRIPT_NAME']);
$file_to_serve = str_replace('.raw','.mp4', $file_to_download); //actually this is the name the 


// make a temporary filename that is unique
$name = 'c:tmptmpfile'.str_shuffle("abcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZ1234567890");
//download the data
$data = file_get_contents('http://remote.com/'.$file_to_download,false);
//store the downloaded data on the disk
file_put_contents($name,$data);
//call the CLI utility
exec('start /B c:programsffmpegffmpeg.exe -i'.$name.' '.$file_to_serve);
unlink($name)
//read the output file
$data =  file_get_contents($file_to_serve);
$size = sizeof($data);

header("Content-Transfer-Encoding: binary");
header("Content-Type: ogg/vorbis);
header("Content-Length: $size"); 
unlink($file_to_serve);

echo $data;

What I’m missing is how to tell the webserver (apache or IIS) "if a ogg file is requested invoke this script" instead of looking on the filesystem for an .mp4 file

Source: Windows Questions

LEAVE A COMMENT