Unable to serve PDF files

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Unable to serve PDF files

Postby laceja » 22. September 2010 18:33

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).

If 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 used to server the file:

Code: Select all
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));
    if (connection_status()!=0) {

Also, if I choose to "Save" the file, the saved file has a length of zero... It's empty.

I'm running an XAMPP installation (PHP 5.3.1 on Apache 2, with the Tomecat plugin) 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 the PHP variables are correct with correct values, using xdebug.

This is driving me crazy.

Please Help!
Posts: 6
Joined: 12. July 2010 18:35

Re: Unable to serve PDF files

Postby Nobbie » 22. September 2010 18:42

Try to use readfile() instead of your opening/reading/printing/closing the file.

Posts: 11620
Joined: 09. March 2008 13:04

Re: Unable to serve PDF files

Postby laceja » 22. September 2010 21:50


use readfile($file_path); instead.
Posts: 6
Joined: 12. July 2010 18:35

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 79 guests