gmacfadden has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -wT use strict; #force all variables to be declared before use use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); print header (-type=>'application/x-octet-stream', -attachment=>'test. +bmp'); start_html (); my $file_name = "file1"; open (INFILE, $file_name) || die ("Can't open ($file_name): $!"); ############################ # print "Hello World as plain text/html before downloading ]<br>\n"; ############################ binmode INFILE; # allow FILEHANDLE read in binary mode $/ = undef; # read entire file not line by line, but in slur +p mode where entire file is read into scalar or array my $data = <INFILE>; # read it into scalar variable close (INFILE); # close input file binmode (STDOUT); # allow FILEHANDLE write in binary mode print $data; # write file to FILEHANDLE STDOUT ############################ # print "Goodbye World as plain text/html after downloading ]<br>\n"; ############################ print end_html (); exit (0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: header (-type=>'application/x-octet-stream') and header (-type=>'plain/html') don't play nicely together
by friedo (Prior) on Nov 10, 2006 at 20:35 UTC | |
|
Re: header (-type=>'application/x-octet-stream') and header (-type=>'plain/html') don't play nicely together
by Fletch (Bishop) on Nov 10, 2006 at 20:37 UTC |