Re: [tangential] Filename via CGI?

Fabrice Scemama (fabrice.scemama@gesnet.net)
Tue, 13 Oct 1998 21:17:50 +0200


At 01:56 PM 10/13/98 +0000, Richard Chen wrote:
>If your browser supports content-disposition (netscape does,
>but ie does not), specify a header line like this:

All Netscape 2.0+ and MSIE 3.0+ support it.

>Content-Disposition: attachment; filename="realFileName"

The minimal header is : Content-type: application/octet-stream.
Content-disposition: filename="foo"  is optionnal, and allows you
to specify a default name for the user when saving the file.
If no filename, the default name will be the name of the script,
which might be surprising for the user.
(As you're sending gzip, why not use MIME type application/x-gzip ?)

>The following is a sample cgi script to use this:
>
>   #!/usr/local/bin/perl
>   open(IN,"</bck/src/rsync-2.1.0.tar.gz") or die;
>   print qq(Content-type: application/octet-stream\n);
>   print qq(Content-disposition: attachment;
>filename="rsync-2.1.0.tar.gz"\n)
>      if $ENV{'HTTP_USER_AGENT'}!~/MSIE/;
>   print "\n"; # print the blank line separating the header from body
>   $/=undef;   # enter whole file reading mode
>   print <IN>; # dump out the binary file
>   $/="\n";    # restore default file reading mode

You forgot to close IN, and the headers' \n are not properly set.
The following script is enough.

#!/usr/local/bin/perl
print "Content-type: application/octet-stream\n";
print "Content-disposition: filename=your_file\n\n";
open (IN, "foo");
print <IN>;
close IN;


HTH
Fabrice