Reputation: 11
On my webpage is the possibilty to download a pdf-file (285kB). The problem is that you download the website as a pdf and not the pdf-file I want to be downloaded.
So I'cant open the downloaded pdf with Adobe Reader but have to open the file with notepad and the content is
<!DOCTYPE html><html lang="en"><he...
Here is the Code for downloading the file:
$filepath = "/download/";
$filename = "filename";
header('Content-disposition: attachment; filename='.$filename);
header('Content-type: application/octet-stream' );
header('Content-Length: '. filesize($filepath.$filename));
readfile($filepath.$filename);
exit;
Can you help me?
Upvotes: 0
Views: 2241
Reputation: 505
did you add the extension with the file name? like this...
$filename = "filename.pdf";
$filepath = "/download/".$filename;
if (file_exists($filePath) {
header('Content-Disposition: attachment; filename='.basename($filepath));
header('Content-type: application/zip' );
header('Content-Length: '. filesize($filePath));
readfile($filepath);
exit;
}
Upvotes: 1
Reputation: 72
Sorry, I can't comment because of my low reputation. That is why posting as answer. You could try with
header('Content-type: application/pdf' );
header('Content-disposition: attachment; filename='.$filename.'.pdf');
header('Content-disposition: attachment; filename='.$filename.'.pdf');
Upvotes: 1