Force Filetype to Download

Follow @tristarweb

Really quick but useful tip today…

I’ll sometimes require the need for certain files on my websites to be automatically downloadable. By that, I mean the user will be prompted to download (or open) the file upon visiting a link to it.

For example, you may have a collection of PDFs, that you want users to download, fill in, and email to you.

Generally with older browsers, filetypes like PDF, DOC, MP3, etc would automatically prompt a download anyway. However, newer versions of Firefox, Chrome, etc, can display documents in browser, playback music, plus a whole lot more.

So, to force a download, you’ll need a htaccess file on your website.

Then simply add the following code to the htaccess:

AddType application/octet-stream .pdf .doc

You can change “.pdf” and “.doc” to different filetypes, or add further filetypes which you only need to separate with a space.

Job done!

About Jack

Howdy... I'm Jack. I have interests in various areas of web design, but mainly you'll find me playing with Wordpress, Magento, and the latest developments in languages such as HTML5 and CSS3. I'm also a keen movie watcher, and regularly watch Newcastle FC lose at the weekend. Check out my blog posts and get ready to be blown away...

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please wrap all source code with [code][/code] tags.

Follow Tristar on Twitter