This might not be entirely obvious, but if you run requests for downloadable files through a PHP routine, then you basically need to load the file and echo it back to the user.
Why would you run a download through PHP you may ask?
What if you wanted to either track or deny the download programmatically?
Or perhaps send a different file back to a different type of surfer
Anyhoo, the unforseen problem can be that if the to-be-downloaded file is huge, then loading it up into memory and squirting it back out to the user may fail because you've exceeded PHP's available memory. Here's how it can be done: (Note that you'd probably get the name/type of this file by other means, like from a DB or the tail of the file, which is immaterial to the example - also, the types of files should be expanded and made more robust - this is just to spin your gears)
<?php
$theFile = 'afile.tar.gz';
$theType = 'tar.gz';
switch ($theType)
{
case 'zip':
$appType = 'application/zip';
break;
case 'txt':
$appType = 'text/plain';
break;
case 'tar.gz':
$appType = 'application/x-gzip';
break;
case 'pdf':
$appType = 'application/pdf';
break;
}
header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($theFile));
header("Content-Type: content-type=$appType");
$f = fopen($theFile, 'r');
while ($buff = fread($f, 8192)) echo($buff);
fclose($f);
?>
Hope that helps,
/p