Back To Resources, Guides and Information

Forcing File Downloads With htaccess

This was posted on 12/01/2010 and was filed in Tips And Tricks, Guides and Information, .htaccess | (No Comments Yet)

I was asked how we could force a user to 'download' a file without using php to alter the header. This htaccess script will force users to DOWNLOAD anything a folder, rather than viewing it in their browser. Really useful when you want to do things like music downloads, image donwloads, etc. because it saves the user the step of File > Save As, then navigating back to your site. The example below applies to ANY file in the directory and any children of the directory that your .htaccess file resides.

<files *.*>
ForceType applicaton/octet-stream
</files>

Simply link to a file in your folder with this snippet, and any file accessed will have to be downloaded. We can even restrict this to certain filetypes. In this case below, it is only applied to mp3 files.

<files *.mp3>
ForceType applicaton/octet-stream
</files>

Have I Helped You? Share Some Love!

Comments

» No Comments have been made on this. How about you start us off?

Comment On This

© Max Morgan Design 2009 - 2012 | Page Generated In 0.17817 Seconds Using 42 MYSQL Queries