Forcing download of a file
Posted: Tue Feb 19, 2008 10:51 am
I have a link on my website to an MP3 file using a standard <a href> tag. But this will redirect the user to the file, and if Apple Quicktime is installed Quicktime thinks it has the right to open the file in the browser and not allow for the option to download. I understand 'Save-As' is on option, but it's not in my case as I redirect to a getFile.php?id=<file ID in database> - so it'll just save the HTML output.
I have tried to force the following headers:
But this doesn't work as I don't have the size of the file for the 'Content-length' header. Could somebody suggest how I get the filesize of the MP3, which is on a different server or another way to go about this.
Thanks in advance,
I have tried to force the following headers:
Code: Select all
header("Content-type: application/octet-stream");
header("Content-Disposition: inline; filename={$url}");
header("Content-length: ".(string)(filesize($url)));
header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");Thanks in advance,