Search code examples
phppdfmime

Downloading PDF - can't open it


I let my users download a PDF-file using this code:

The $db->Record['file'] contains the relative path to the document.

The access a dummy page that loads the pdf, so they do not actually see the "text.pdf" in the url. I changed the headers of the file to achieve this:

$downloadfile = '/data/srv/www/vhosts/htdocs'.$db->Record['file'];
$filename = basename($downloadfile);        
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.$filename.'"');        
readfile($downloadfile);

The download works without any problems, but when I try to open it, the following error ocurrs:

The PDF file could not be openend, the type is not supported or the file
was damaged.

How can I fix this?

Not: When I download the file directly, meaning to access is via http://.../text.pdf and open it, everything works fine.


Solution

  • (Copied from the comments) I'll bet a beer there are PHP error messages in the file.