Viewed 11k times. Improve this question. Community Bot 1 1 1 silver badge. Add a comment. Active Oldest Votes. Improve this answer. This will work only in some browser. Safari is not one of them! I needed this in my Wordpress site and it worked perfectly! Thank you! Thanks a lot jord8on. I am feeling good to heard that solution help you. Now it auto download so people open it with adobe or else. Show 2 more comments. Sign up or log in Sign up using Google. Sign up using Facebook.
Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. This code was the perfect starting place to get this functionality built in. Thank you!!! The download code working fine but my downloaded PDF file is always zero bytes and not opening with a pdf reader. Any suggestion? Your email address will not be published.
Notify me of follow-up comments by email. Notify me of new posts by email. This site uses Akismet to reduce spam. Learn how your comment data is processed. Plugins Themes WordPress. On the lines after we checked that the file exists, we are cleaning the result, getting the filename and the extension.
The extension is important because we can then check if this extension is allowed for download. We are also using the extension to set the right headers to send from the server. After that we are creating a variable called whitelist. This variable will be used to define an array with all the extensions that are available for download.
We are also applying a filter which can be used to extend this array or not. How to use WordPress filter can be learned here. After that we are checking if the file is allowed and also to check if the file is not a php file just to be sure. If those checks pass we are setting the content type for the headers we will send from the server.
We are also applying a filter to this variable and we are also passing an additional parameter which is the extension. By using this filter together with the filter before we can extend this functionality and enable other files for download.
When everything is set we are sending to our user different headers with the file for download. Like this: Like Loading All Posts Website. Share this: ManageWP. After that this code worked as treat, so, many thanks! Igor Benic May 24, at am. Thank you very much for that! I saw the errors in the code and corrected them. Nathan Hawkes September 26, at am. Igor Benic September 27, at am.
Hi Nathan, thank you for the comment. That might be a much better way of handling it, I agree! Hope that helped or gave you an idea on how you could handle that: Reply. There ist nothinh happening when the url changes— Reply. Igor Benic October 18, at pm. Arun February 15, at pm. Igor Benic May 7, at pm. Maybe something changed in WordPress. TB May 7, at am. Algeria September 14, at pm. It works, great scripts, thanks Reply. Arjen November 1, at pm.
0コメント