SPUG: Content-Dispostion http header

David Innes (CSG) davidinnes at chicagoscience.com
Fri Feb 15 18:31:38 CST 2002


Dan said:
Oh, well.  It works in Netscape, and will only be used by one person anyway.
I'll tell him to use Netscape :)

I say:
Aww why take it out on him? :-)  Here's a quickie script that works with
Explorer (with the Feb. 13th security patch anyway, I don't know about
earlier versions.)  There are surely better ways to do it but it worked this
way when I needed it.

#-----------------------
use strict;
use CGI;
use CGI::carp;

my $filename = "test.txt";
open FILE, $filename;

binmode FILE;
binmode STDOUT; #you could probably just say 'binmode;' but I didn't

my $q = new CGI;
print $q->header( -type => "application/notepad", -Content_disposition =>
"attachment; filename=$filename");

my $buffer = "";
while ( read( FILE, $buffer, 1026) ) { print "$buffer"; }

close FILE;
#-----------------------

Good luck
        -- David Innes


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list