This is an oldie but a goody. In web development there comes a time when you need to force a download when someone clicks on a link, without telling them to “right click save as…” In the past this was always a problem. Now thanks to Google, you can type in keywords and find a nice, lovely blog post like this one and figure it out. And of course you’re not going to tell anyone because you want to look like a Rock Star. So you’re going to say “ain’t nothing but a thang.”
And before you do that, here’s how you’re going to save the day and prompt a “Save As” to the user so he/she can download his/her file:
# Put all your extensions after the word stream
AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4 .xlsx .docm
Put the preceding code in your Apache config or your .htaccess file. And be sure to enable .htaccess if you don’t already have it enabled.
Again, just do something like this. And by the way, you can even create “fake” extensions if you want. Trust me, sometimes you want to make things up.
# AddType application/octet-stream
AddType application/octet-stream .xml
Note, I’ve had bad luck with IE6 using .txt as an extension. But don’t worry because IE6 is evil and anyone using it is infected with a virus.
That’s it for now. Stay tuned to my blog. I’m in the process of writing some PHP to better handle .htaccess files.