I've been struggling with a problem for several days now. I'm trying to serve a PDF file and, when I try to "Open with Adobe Reader...", I get an error that says:
Could not open "filename.pdf" because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
I double click on the original file, in my file system, it opens without any problems in Adobe Reader.
Here's the relavent PHP code:
session_cache_limiter('must-revalidate');
header("Pragma: public");
header("Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
header("Cache-Control: private");
header("Content-Description: File Transfer");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"$asfname\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);
$file = fopen($file_path,"rb");
if ($file) {
while(!feof($file)) {
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
fclose($file);
die();
}
}
fclose($file);
}
I'm running PHP 5.3.1 on Apache on a WindowsXP machine. I have verified that "extension=php_pdflib.dll" is in my php.ini and is not commented out. My browser is Firefox 3.6.10. I doubt the problem is with the browser because, I have no problem downloading and opening PDF files from external sites. I have also verified that all variables are correct and values are correct, using xdebug.
This is driving me crazy.
Help!