Nearly every browser will show image oder video files you want to provide for download in the browser itself instead of opening a download dialog.
Most of the websites suggest to use this code in your .htaccess:
But this is not enough! Even when the MIME-Type is set to “octet-stream”, some browsers will still open the files their selfs because they have detected the .jpg or .avi file extension.
The solution to this is to add the following header:
With this header every browser i tested opened a download dialog, regardless of which file extension is present.
To use this, your webserver has to have mod_headers activated (It is most likely already included in Apache, but not activated): Apache Module mod_headers
Posted by TimeWaster Programming apache , config , download , force , htaccess , picture 20 Comments
Loren says: 27.02.2013 (February 27) at 19:11 Is it possible to target a specific browser (Firefox 19) with this approach? Reply
Is it possible to target a specific browser (Firefox 19) with this approach?
TimeWaster says: 28.02.2013 (February 28) at 06:51 I have no idea. Take a look in the apache documentation, if there is a way to check for browsers it will be described there. Reply
I have no idea. Take a look in the apache documentation, if there is a way to check for browsers it will be described there.
Loren says: 28.02.2013 (February 28) at 18:40 Thanks for the quick response. I’ll do that. Reply
Thanks for the quick response. I’ll do that.
Simpleguy says: 21.08.2013 (August 21) at 16:13 You need to enable Apaches ‘headers_module’. Reply
You need to enable Apaches ‘headers_module’.
Jay says: 16.09.2013 (September 16) at 04:45 Hey everyone having 500 errors. The 2nd line requires the Apache Mod_Headers. So either add it yourself if you’re on a VPS or get on the phone to your webhost! Good luck, J Reply
Hey everyone having 500 errors. The 2nd line requires the Apache Mod_Headers. So either add it yourself if you’re on a VPS or get on the phone to your webhost!
Good luck, J
shankar says: 17.09.2013 (September 17) at 16:17 it’s showing Internal Server Error anyone help? Reply
it’s showing Internal Server Error anyone help?
TimeWaster says: 17.09.2013 (September 17) at 16:27 @shankar: take a look at the updated article above. Reply
@shankar: take a look at the updated article above.
Pingback: php – How do I force a jpeg image to download instead of open in a browser window? | Asking
Elad Karako says: 13.01.2016 (January 13) at 07:25 nice answer, I’ve wrapped it with some stuff for the following answer at: http://stackoverflow.com/a/34758866/257319 Reply
nice answer, I’ve wrapped it with some stuff for the following answer at: http://stackoverflow.com/a/34758866/257319
Pingback: Htaccess Force Download
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
This site uses Akismet to reduce spam. Learn how your comment data is processed .
GitHub: Chamfers for OpenSCAD
GitHub: Snake for MicroView
GitHub: TV Screen for MicroView
Thingiverse: Chamfers for OpenSCAD
Thingiverse: Pulley for Geeetech Prusa i3 B+C Idler Belt Tensioner
Devilmastah's Blog
© 2019 TimeWaster's Place