Re: [tangential] Filename via CGI?

Richard Chen (richard@lexitech.com)
Tue, 13 Oct 1998 13:56:37 +0000


If your browser supports content-disposition (netscape does,
but ie does not), specify a header line like this:

Content-Disposition: attachment; filename="realFileName"

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

Walter Ian Kaye wrote:
> 
> I really don't know where to ask this, but I figure someone here must
> know the answer. :)
> 
> For a "download.cgi" script that returns a file to the user, how do you
> specify a filename so it doesn't download as "download.cgi"? I know how
> to send the MIME type, but how can a script indicate the filename?
> 
> thanks,
> -puzzled in CA

-- 
Richard Chen
Lexitech Multimedia
203-483-2895 ext 232
richard@lexitech.com