How to get PDF to beginner download

Possible duplicate:
How to automatically download a PDF file?

I checked the other forums, but I do not understand what they say. I checked this link, which people seem to get the solution:

http://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/

I want to make a button that executes to download a PDF file, the file is too large to see it on the Internet. Therefore, I want this button to force the browser to download the file. Ask or not ask the user. There will be different PDF name files, so I need to make this button downloadable with PDF formats of various PDF files.

I have checked different websites and it seems like it can be done with htaccess, but I honestly don't know how to do it. Can someone help me show how I can do this!?!?! Is there an easy way using CSS / html ??

I lingered for such a small detail for a long time.

My code is simple:

<div class="Container for icons"> <a href="hugefile.pdf" alt=""><img href="icon.png" alt=""/> </div> 

Can someone give me a hand on this?

+3
source share
2 answers

You will need to change the HTTP header returned to the client in order to accomplish this:

Here is a sample PHP code:

 $path = "path/to/file.pdf"; $filename = "file.pdf"; header('Content-Transfer-Encoding: binary'); // For Gecko browsers mainly header('Last-Modified: ' . gmdate('D, d MYH:i:s', filemtime($path)) . ' GMT'); header('Accept-Ranges: bytes'); // For download resume header('Content-Length: ' . filesize($path)); // File size header('Content-Encoding: none'); header('Content-Type: application/pdf'); // Change this mime type if the file is not PDF header('Content-Disposition: attachment; filename=' . $filename); // Make the browser display the Save As dialog readfile($path); //this is necessary in order to get it to actually download the file, otherwise it will be 0Kb 
+10
source

Instead of AddType you can try ForceType :

 <FilesMatch "\.(pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch> 
+5
source

Source: https://habr.com/ru/post/1400357/


All Articles