I have been learning PHP for a while now, and recently, i found out that many people asks for downloading PDF files and problems they experience. Well, I've manage to spend some time into this, maybe it will help. I have many operating systems and different types of browsers installed on them.
First of all, i think they've fixed the attachment; bug and so it is REQUIRED to use the word attachment; in the header("Content-Disposition: ...) or else IE will not prompt for download.
Secondly, many people used the header("Content-Length: ...".filesize($filename)); in their script, and this will cause Windows 98(SE)/ Win95 / Win ME with internet explorer 5.x fail to download the PDF file. The result of this will be a 0 byte file since the filesize($filename) did not return any values at all. So if you just leave it out, everything will work fine. (BTW: why specify it anyway??!!??)
Thirdly, I used header("Content-Type: application/RFC822"); and not octet-stream.
Below is the script i used for my web site. Hope this helps.
Note: The script below must be executed by a GET method with parameters $WEBSITE, $PATH, $FILENAME.
=============================================
<?
header ("Pragma: no-cache");
header ("Expires: 0");
header ("Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0");
$full_file_path = $WEBSITE.$PATH.$FILENAME;
// --- debug purposes --- echo(filesize($full_file_path));
if (($REQUEST_METHOD != "GET") || !isset($FILENAME) || ($FILENAME == NULL)) {
header("Location: ".$WEBSITE);
exit();
} else {
// --- Do Not Use --- header("Content-Type: application/octet-stream");
header("Content-Type: application/RFC822");
header("Content-Disposition: attachment; filename=\"".$FILENAME."\"");
// --- Do Not Use --- header("Content-Length: ".filesize($full_file_path));
@readfile($full_file_path);
exit();
}
?>
=============================================