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, and must translate them on the fly exposing them like

Doing so when someone goes to the site connects to 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(''.$file_to_download,false);
//store the downloaded data on the disk
//call the CLI utility
exec('start /B c:programsffmpegffmpeg.exe -i'.$name.' '.$file_to_serve);
//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"); 

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