#! /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 ]
\n"; ############################ binmode INFILE; # allow FILEHANDLE read in binary mode $/ = undef; # read entire file not line by line, but in slurp mode where entire file is read into scalar or array my $data = ; # 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 ]
\n"; ############################ print end_html (); exit (0);