Force a file to download

Image by: vizzzual-dot-com
In building CMS sites for clients, some may require that you offer certain files to be downloaded off their site. A PDF for example, or perhaps wallpapers or other media. Most browsers, correctly, will display these items inline as a new page or tab however for these purposes you need to force the browser to download the item, not display it. Here’s how it’s done.
The Code
Your .htaccess file is the key to getting this done, and here’s the code you need to add:
AddType application/octet-stream .csv AddType application/octet-stream .xls AddType application/octet-stream .doc AddType application/octet-stream .avi AddType application/octet-stream .mpg AddType application/octet-stream .mov AddType application/octet-stream .pdf
You can of course add as many other filetypes to this list as you may require, but you can get the principle from this example.



Thanks. I really appreciate this. I have a website that I put songs I’ve made on it and I’ve been looking for a way to make this work. thanks to you I can.
Awesome! Spent all day looking for this! Thanks a lot. I am bookmarking your page now!
F*ckin’ tremendous things here. I’m very glad to look your post. Thanks so much and i’m having a look ahead to contact you. Will you kindly drop me a mail?
Works perfect. Thank you.
thanks for sharing!!!
this is all what we need to bypass those bloody paid site
Opens up a blank page in chrome…not totally stable. I found this to be the solutions for all browsers:
ForceType application/octet-stream
Header set Content-Disposition attachment
Just delete the ** marks (but keep the one inside next to .pdf) and copy/paste into .htaccess
****
ForceType application/octet-stream
Header set Content-Disposition attachment
****