I see no reason why this wouldn't work. I have pretty much the same code in a project I'm currently working on, which works fine.
I'm not entirely sure what the zlib compression stuff is doing there, but I can't see how that would mess this up.
Unless you also forgot to replace the $f_name in the filesize() function?
This is the code I'm using. As I say, it's pretty much identical to yours but I have tested it and it works perfectly. (Running Fedora 7 using PHP 5.1.6)
-
<?php
-
$filename = "path/to/file/filname.ext";
-
-
if(!file_exists($filename)) {
-
die("File does not exist!");
-
}
-
-
header("Pragma: public");
-
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
-
header("Cache-Control: private",false);
-
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
-
header("Content-Transfer-Encoding: binary");
-
header("Content-Type: PHP Generated Data");
-
header("Content-Length: ".filesize($filename));
-
readfile("$filename");
-
exit();
-
?>
-