IE7 php force download FIX

Normally, as anĀ  accomplished programmer, you use all the headers, follow the guidelines, include what you should…

but, when Microsoft won’t play by the rules, you have to fudge…

IE7 rejects forced downloads (in this example I was using doing PDF, mp3, zip, and m4b files).

It opens the download dialog, chooses a location, and then commences to quit having downloaded 0 bits.

So, instead of the dutiful example elsewhere in this blog that chooses the correct content-type, length, transer encoding and so on…

We just do this, seems to work, forces it somehow, sorry, I’ve no further explanation…:

<?

$filename = $_GET[‘file’];
// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);

$file_extension = strtolower(substr(strrchr($filename,”.”),1));
if( $filename == “” )
{
echo “<html><title></title><body>ERROR: download file NOT SPECIFIED.</body></html>”;
exit;
}

header(“Cache-Control: maxage=1”);
header(“Content-Type: application/force-download”);
header(“Content-disposition: attachment; filename=\””. $filename .”\”;” );
@readfile(“$filename”) or die(“File not found.”);
exit();

?>

Comments are closed.