[Wolves] Apache question

Aquarius aquarius-lists at kryogenix.org
Fri Jan 23 07:17:27 GMT 2004


James Turner spoo'd forth:
> Like all things, it's probably dead easy if you know how, but...
> 
> One of my friends is working on a web site which amongst other things will 
> include a section that provides (legal) MP3s for download. How do you ensure 
> that when a user clicks on a link to one of the MP3 files their browser 
> always begins to download the file rather than trying to load it into a media 
> player (etc)?
> 
> As a temporary measure, he is providing users with instructions to right-click 
> on the links and select "Save link target as..." (or whatever the IE 
> equivalent is) but it would be far better if they could just left-click. Does 
> the solution lie in something to do with setting the content type?
> 
> The web server is currently running Apache 1.3 on FreeBSD.

It's a bit fiddly. Mainly because you are not supposed to be able to do this. :)
The browser is supposed to be able to deal with content any way it chooses.
On the other hand, the situation is also complicated by (guess what?) IE.

If the world was standards-compliant, then IE wouldn't open things called "foo.mp3"
in a media player; it'd open things with the mp3 content-type in a media player, 
no matter what they are called. However, because people don't care enough about
getting content-types right (this is why some sites' wmv files will open as text
in Mozilla) IE keys off the filename as well. So, you need to do some server-side
stuff to do this. Essentially, you have to set the Content-Disposition to
show that the file you're downloading is an attachment, and then stream the
binary data. 

See http://uk2.php.net/readfile for a php example.

Aq.

-- 
Can i dial 1-255-255-255 and make every phone in the world ring?
	   -- Tanuki



More information about the Wolves mailing list