views:

1030

answers:

4

I have links to mp3 files on my website (normal <a href="file.mp3"> tags).

But for many users who have QuickTime installed, it will open the mp3 files rather than "save" them when you click on the links.

Can you force the browser to save the link rather than using the browser preference?

I can use JavaScript or C# .NET but I'm looking for the simplest solution (if even possible)

Thanks in advance.

A: 

I don't think you can do this easily. In addition, you shouldn't do this. The machine belongs to the user and, if they'd prefer to stream your MP3s rather than downloading them, it's their decision.

My own solution would be to provide a link for people to complain that they're streamed rather than downloaded (well, complain about anything, really) and let the community (including yourself) provide solutions.

Then, if someone states that it always seems to play rather than download, you can work with them to figure out they're using Firefox and QuickTime and tell them they can either right-click-save-as or reconfigure Firefox.

I will say that there will be ways in which you can achieve this, such as changing the MIME type or file name that's sent down, but my comment that this should be under the control of the user stands. And anyway, a determined user can quite easily re-configure their browser to stream whatever MIME type you decide to use so you still can't guarantee it.

paxdiablo
A: 

It's impossible to absolutely force it, but you can try adding the line to your apache config:

AddType application/random-fake-type .mp3

It is my understanding that IE looks at a request and tries to guess the MIME type so the above workaround won't really work. You can also write a script to handle this for you, just like this similar php script.

Andrew Austin
+1  A: 

Just add a Content-Disposition header to your page!

Here's a simple .htaccess rule to do this:

<FilesMatch "\.mp3$">
Header set Content-Disposition attachment; filename=downloaded.mp3
</FilesMatch>

The downside to this though is that your downloaded files will have the same name in the "save-as" dialog box. This might work without the filename part, but I haven't tested it. (Although I didn't test the rest of this as well... ;P )

Edit: Also, if you have server-side scripting available, you could use that to get the name of the file and set the Content-Disposition header.

MiffTheFox
+2  A: 

You need to set a http header with "Content-Disposition" set to "attachment". This will force the browser to pop a save dialog. 873207 has a clean way of doing this.

BUT, like Pax says, you probably shouldn't do this by default. A nice way of doing it is to provide a normal link to the file (the way you're doing it), and provide a secondary link beside it that forces the save dialog. That way you let the "less gifted" users do a simple click-to-save operation, as well as let every other user do whatever it is they want with the mp3.

Dan F