Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a cgi script which is used to both link to and then pipe the file to the user. It creates the link as follows:
<a href="http://www.myserver.com/cgi-bin/my_script.pl?filename">filena +me</a>
when this link is clicked on and the file is downloaded it wants to save the file as "my_script.pl" instead of the real filename. I tried setting "Content-Name: $filename", but it didn't work (probably since it brings the save-as box up before the file is really sent).

What is the best way to go about solving this problem?

Replies are listed 'Best First'.
Re: HTML File Naming Problem
by blokhead (Monsignor) on Jan 21, 2003 at 15:26 UTC
    For downloadable links (not HTML pages), I've had luck with setting headers like this:     Content-Disposition: attachment; filename="xyz.gif" Keep in mind there's nothing you can do if the user shift-clicks -- it will be saved as 'my_script.pl'. As you say, the save-as dialog will pop up before it gets any of your headers.

    Perhaps a cleaner way of all this is to have a ScriptAlias for my_script.pl in your apache httpd.conf. Then you can make links to /cgi-bin/my_script.pl/filename, and the browser will make a better guess in the save-as dialog.

    blokhead

      This works nicely, except with Netscape 4.x. Perhaps, it will be incentive for people to finally upgrade.
Re: HTML File Naming Problem
by valdez (Monsignor) on Jan 21, 2003 at 15:38 UTC