Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Filename in HTTP header?

by Anonymous Monk
on Aug 07, 2000 at 03:45 UTC ( [id://26472]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all,

I'm working on a CGI script that returns small files with some (text) info.

Is there a way to give the outputted result a different filename? (I don't want them to be called download.pl when users download them, more like $name.$extension)

I figured there must be a HTTP header for this purpose but I couldn't find it anywhere :-(

btw, I can't receive my password when I register an account at PerlMonks ... is the script b0rked or is my mail server confused?

Thanks in advance, CBAS

Replies are listed 'Best First'.
Re: Filename in HTTP header?
by nardo (Friar) on Aug 07, 2000 at 04:01 UTC
    Don't know if there's a header to set the name, but you can link to your script with http://host/cgi-bin/example.cgi/filename to cause the browser to think it's viewing filename. If you can't link to a static filename, you could have the cgi print out a Location header at runtime.
Re: Filename in HTTP header?
by merlyn (Sage) on Aug 07, 2000 at 04:50 UTC
      "if adventurous use Archive::Tar and Compress::Zlib to generate compressed archive without external program. (Perhaps in a future column.)"

      If you do write that column, Merlyn, would you be so kind as to let the Monastery know? Or if this RE:(2) gets --, then s/let Monastery know/let ybiC know/   ;^)


          where's a personal drummer when you need one?
          ybiC

        I believe we would all benefit from merlyn's wisdom, so if he would be so kind as to write the column so we can all view it. merlyn, you are not JAPH.

        J. J. Horner
        Linux, Perl, Apache, Stronghold, Unix
        jhorner@knoxlug.org http://www.knoxlug.org/
        
      Wow, thanks! I never expected to get such an answer :-)

      I didn't understand your code completely (I'm new to Perl) so I might be wrong about this but would the script run into trouble when more than one request is made in the same second (like when a user double clicks the submit button)?

      And how does the script keep old files away? I don't have that much diskspace so old files have to be removed like every hour or something ... maybe I'll run a check on the previous filenames when the script is run and remove any that are too old. (?)

      Anyway, thanks for your help, I really appreciate it becasuse this thing got me stuck for a few hours :-(

      Sorry for the bad spelling, English isn't my first language ... or my second ;-)

      Thanks,
      CBAS

Re: Filename in HTTP header?
by yoz (Initiate) on Sep 23, 2003 at 17:36 UTC

    The header you're looking for is:

    Content-Disposition: attachment; filename=[FILENAME]

    Saves all that tedious mucking about with URLs.

    -- Yoz

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://26472]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found