Forum Moderators: phranque
Anyone know how I can get the the "File Save As" window to open when clicking a link to a file?
Example....
I have MP3's that I want folks to download. I don't want their MP3 Player to detect it and play the file, I just want them to download it.
What's the code gotta look like?
Thanks~
Guy
There are probably other ways also. The key is that you need to be able to specify that the content is an attachment. I think the specific header for this is the "content-disposition".
An alternative is to adjust the content-type (mime type) to something that the browser won't link to a plug-in. I don't recommend the second option though because the mime-type will stick with the file when they save it.
The reason that the user is not automatically prompted now is that the server sees the .mp3 extension and then sets the HTTP header for the content-type as binary/mp3 (or something like that). When the browser gets the file, it sees this mime-type and invokes its plug-in or helper app for mp3 files.
The key is that you need to be able to specify that the content is an attachment. I think the specific header for this is the "content-disposition".
That is how it is supposed to work. In my experience IE is not very co-operative here. It tends to ignore what you tell it about how to handle a file type, and tries to open it in any case. In IE, the result of changing the headers may be downloading the source page rather than the file! (Further complicating matters, every version of IE has done this a bit differently, so any "workaround" is sure NOT to work with some versions of the browser.)
Nonetheless, the approach will work for other browsers, so you may think it worth it, and just live with IE's insubordination.
If you absolutely must force a download, the only way IE seems to fully respect directions (other than installing an applet to handle the downloads) is to zip your file, and have the user download it as such. But I doubt that's what you have in mind.
One other option: instruct visitors to right-click and use "Save target as. . .". This asks a little bit more of your users (and I don't necessarily recommend it), but it will might work to get them exactly where you want.