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

Hello Monks,

Is there a Perl module or work-around for overcoming the different ways various browsers handle files offered for download?

While googling for an answer to this I ran across this bit of info on Matt's Script archive:

If your browser attempts to name the downloaded file download.cgi you should save it to disk and then rename it with the appropriate extension. This bug has been reported in various browsers, including IE for Mac OS X.

I've found that on win, IE6, NS7 work fine, same for phoenix 0.5 on RH Linux. On win IE5.5 I get the bug referenced in the info above.

Any hints would be appreciated.

- D

Replies are listed 'Best First'.
Re: downloading files, different browsers
by Coruscate (Sexton) on Feb 21, 2003 at 05:31 UTC

    You'll want to take a look at the Content-Disposition HTTP header. This perlmonks post shows an example of how to use its powers :)


    If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.

      And see RFC 2183 for all the "official" details.

      Arjen

Re: downloading files, different browsers
by Cabrion (Friar) on Feb 21, 2003 at 12:52 UTC
    I recall getting bit by that bug a while back. I never worked out how to detect the minor version number in the browser to make things automated; I put up two links and let the user decide if they had IE 5.51.

    I seem to recall that there was some JavaScript that you could use to detect IE minor versions, but I never tried it. The difference was, for IE 5.51 do this . .

    print "Content-Disposition: filename=$filename\n\n";
    instead of this.
    print "Content-disposition: attachment; filename=$filename\n\n +";
    after the Content-Type line.

    Microsoft acknowledges the bug. . . how nice.

    And I just remembered one last quirk. By not being able to use "attachment" IE 5.51 reads the first few bytes of a file to determine it's type (it ignores your Content-Type MIME Header!) and if it recognizes say MS-Word or MS-Excel it would open the file in the browser instead of generating a "save as" dialog. However, if the user does a file->save from the menu it will have the right name.

      Groovy baby.
      Now I have this working in most of the browsers that my target users will be using.

      Thanks,

      Thanks to all for their input.

      - D