Re: File downloads from php


Subject: Re: File downloads from php
From: Michael Fowler (michael@shoebox.net)
Date: Sat Jun 22 2002 - 22:08:57 AKDT


On Sat, Jun 22, 2002 at 05:55:36PM -0800, Grant Stockly wrote:
> Anyone offhand know how to pass a different file name to a browser when
> they try to download the link?

I'm not sure what you mean here. Do you mean you want them to be able to
click the link and get one file, but if they right click and select "Save to
file" (or the equivalent in their browser) they get a different file?

If this is the case, there's no way I know of to do this on the server side.
The request looks the same either way. You could possibly manage it with
JavaScript or other client-side programming, but I couldn't tell you how.

> I want to let users download 30 second mp3's stored in a mysql database.
> My first thought was just to create add *mp3 to apache as a php script and
> then make a php file called something like "song.mp3" where the table and
> ID were passed to the "song.mp3" script by POST.

If all you want to do is allow the user to download the file from the
database when they click the link then I should be able to help. Typically
this is done with images, but it's simple enough to extend to any other
format.

Just specify, as the URL, a call to a PHP script with the necessary
information in it. Say, for example:

    <A href="/get-mp3.php3?id=1&table=mp3s">song.mp3</A>

get-mp3.php3 should then retrieve the requested MP3 from the database and
dump it back. Be sure to set the content-type to the appropriate value
(audio/mpeg according to my /etc/mime.types) so the browser understands what
to do with it.

This applies equally well to a CGI script, a mod_perl module, or whatever.
I used PHP in my example because that's what you mentioned.

Michael

--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

--------- To unsubscribe, send email to <aklug-request@aklug.org> with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Sat Jun 22 2002 - 22:08:27 AKDT