Download .pdf

I have pdf files for download on my site. And when I click on the link, the browser opens the file in a separate tab. I need to get the window -Open – Save … or immediately download this file. Help with code


Answer 1, authority 100%

There was already a similar one on the forum question, look. It is possible to implement what you need through .htaccess

<FilesMatch "\.(?i:pdf)$">
     ForceType application/octet-stream
     Header set Content-Disposition attachment
</FilesMatch>

Answer 2, authority 33%

Your question is also similar to this. The solution might be:

1 There is a php page with this code:

$file_name = "files/file.pdf";
header("Content-disposition: attachment; filename=$file_name");
header("Content-type: application/pdf");
readfile("{$_SERVER["DOCUMENT_ROOT"]}/$file_name");

2 Where you had a link to a pdf like href="files/file.pdf"there should now be a link like href="download.php".

PS It might be better to use “header("Content-type: application/force-download");” as the third line.


Answer 3

An option is to pack it into an archive, without unnecessary red tape.