Forum Moderators: phranque

Message Too Old, No Replies

Force download dialog

         

slazenger

6:31 pm on May 4, 2011 (gmt 0)

10+ Year Member



I need to force a link to open the download dialog box instead of opening in the browser. I have tried adding each of these to .htaccess:

AddType application/octet-stream .mp3


<Files *.mp3>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>


<FilesMatch "\.(?i:mp3)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>


With no result. In fact, the only thing that has gotten me anywhere is

ForceType application/octet-stream
Header set Content-Disposition attachment


which forces every page on the site to download, which is obviously not what I want. I have seen implications that I may need to enable mod_header, but I have not found any instructions on how to do that.

Please don't say to just tell the user to right click+save as, because this is not an acceptable solution to the client. If I could just put up that message, I wouldn't have spent the past week trying to solve this. Also, .zip files are out.

Thanks.

lucy24

10:43 pm on May 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you try the simpler form

<FilesMatch "\.mp3$">

Quick-and-dirty way to confirm that you have mod_headers installed (you probably do, unless you are running a truly ancient version of Apache):

Make a directory with any name. Give it an .htaccess that says
<IfModule mod_headers.c>
SetEnv MOD_mod_headers 1
</IfModule>

(The version I've got checks for 96 known mods in one fell swoop. But you don't need the whole list.)

Make an index.shtml that says, in full
<!--#printenv -->

Upload the directory and open in your browser. Look for a line that says
MOD_mod_headers=1

Now quickly delete the directory before you forget ;)

slazenger

1:27 pm on May 6, 2011 (gmt 0)

10+ Year Member



<FilesMatch "\.mp3$">
worked! Thank you so much.