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

In a nutshell I have a CGI script which creates a TAR file dependent on the inputs. What I want to happen is when the script is run it returns the tar file, as if it has been downloaded from the server. I know I need to first print the correct HTTP header, however the file is always named of that of the script. I want it to be called as something of my choice such as serialise.tar instead of serialise.cgi. Is there a module that takes care of this, CGI.pm's manpages don't seem to mention anything !!! I may just be being a muppet but any help thankfully received.

Replies are listed 'Best First'.
Re: Downloading a dynamically created file
by Kanji (Parson) on Feb 07, 2002 at 16:24 UTC
      Kanji - point taken
      Must use super search before bothering monks Must use super search before bothering monks Must use super search before bothering monks Must use super search before bothering monks Must use super search before bothering monks
      But seriously thanks all that replied solved my problems in one nice and easy step
Re: Downloading a dynamically created file
by BazB (Priest) on Feb 07, 2002 at 16:11 UTC

    I'd probably have two pages, the first one that takes the users input (depending on your application could be plain HTML), the second (CGI script) that returns the content type for the tar file (I'd have to RTFM for the correct Content-type:) and the file itself.

    Since the browser is being fed the Content-type: for a tar file, it will handle it as the user expects (normally by offering to download it).

    Changing the Content-type: header is demonstrated in the CGI docs.

    Hope that helps.

    BazB.

    Update: merlyn's column, referenced here suggests Content-type: application/x-tar-gzip (for a .tar.gz file).
    application/x-gtar or application/x-tar might also be applicable if the tarball is not compressed.

Re: Downloading a dynamically created file
by merlyn (Sage) on Feb 07, 2002 at 16:36 UTC