-
AuthorPosts
-
April 27, 2017 at 1:03 pm #783991
Hi !
I’d like to add a button or an image to download a pdf file when I click on it (not open in a new tab, but download directly). Is there a way to do this ?
Thanks,
FranckApril 29, 2017 at 5:38 pm #785046Hey SphereEvenements,
Could you please give us a link to your website, we need more context to be able to help you.
Best regards,
VictoriaMay 2, 2017 at 10:01 am #786252Hi Victoria,
For sure : http://www.sphere-evenements.com/
Thanks,
FranckMay 2, 2017 at 1:35 pm #786328here is something i found on this thematic:
You can’t do this with HTML.
It’s a server-based solution. You have to stream the file so that the browser than triggers the save dialog.I’d advise not doing this. How a user interacts with a PDF should be left up to the user.
And i do agree to that on security reasons. (pdf bomb)
PS: on html5 now it seems to be able to do that . But on the security reasons i stay on my oppinion that it is a “no go” –
Link : https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-downloadbut you can do it with zip files – than the user has the opportunity to have a first look to the downloaded zip file (Antivirus etc.)
- This reply was modified 7 years, 7 months ago by Guenni007.
May 2, 2017 at 6:02 pm #786595Hi,
thanks as always @Guenni007 :)
@SphereEvenements
Let us know if the link he provided is useful to you. In general it’s more about a WordPress question than a theme related one. So maybe there is a plugin out there for you. You could also ask this in general WP support forum, as they may know a solution for you.Best regards,
AndyMay 4, 2017 at 10:32 am #787686Hi @guenni007 and @Andy,
Thank you for your response. I’m not sure I understand why it is “dangerous” to do this with HTML ?
Thanks,
FranckMay 4, 2017 at 11:40 am #787719Is there a security problem if I add a htaccess in the folder of my pdf with this ?
AddType application/octet-stream .pdf
Thanks
FranckMay 4, 2017 at 10:54 pm #788115Hi,
No, there shouldnt be any issue at all with that.
Best regards,
BasilisMay 5, 2017 at 1:22 pm #788368try first to set a link with for example:
you see in the link the download=””<a href="https://domain.de/xyz.pdf" download="Aufsatz_ueber_Nettiquette.pdf">Nettiquette</a>
this will be the html5 method and it works now on Firefox, Safari, Opera, Chrome : https://webers-testseite.de/kokon/this-is-a-post-with-post-type-link/
Or for a globaly solution: you use this in htaccess file:
<FilesMatch "\.(?i:pdf)$"> # Force File Download ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
- This reply was modified 7 years, 7 months ago by Guenni007.
May 5, 2017 at 2:00 pm #788380if you like to include other files to do the same:
<FilesMatch "\.(?i:(pdf|xls))$"> # Force File Download ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
you know that from the rule concerning to cors :
<FilesMatch "\.(ttf|otf|woff)$"> <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" </IfModule> </FilesMatch>
- This reply was modified 7 years, 7 months ago by Guenni007.
May 9, 2017 at 10:21 am #790110Thank you Guenni, but what is the difference between my htaccess code and yours ?
Thanks,
FranckMay 9, 2017 at 11:13 am #790142you mean your one liner :
AddType application/octet-stream .pdf
if it works – ok.
but some browsers have some trouble with .PDF or the IE does something else you are intend to do.
I think the code will work browser independent:<FilesMatch "\.(?i:pdf)$"> # Force File Download ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
to be more precise it should be:
<FilesMatch "\.(?i:pdf)$"> <IfModule mod_headers.c> ForceType application/octet-stream Header set Content-Disposition attachment </IfModule> </FilesMatch>
but test yourself
btw: the ?i: is for beeing independent from upper/lowercase combinations.- This reply was modified 7 years, 7 months ago by Guenni007.
May 15, 2017 at 5:19 pm #793429Ok thank you @Guenni007
May 15, 2017 at 10:02 pm #793542Hi,
Has that worked, do you need anything else from us?
Best regards,
BasilisMay 16, 2017 at 10:23 am #793795Hi,
No thank you very much for your help !
FranckMay 16, 2017 at 12:35 pm #793862 -
AuthorPosts
- You must be logged in to reply to this topic.