sub send_file {
my ($cgi, $dir, $file) = @_;
my $path = "$dir$file";
$cgi->charset('');
#$|=1; ### THIS FOULS UP THE DOWNLOAD "SAVE AS..." DIALOGUE
$|=0; #SO LET'S BE EXPLICIT ABOUT SETTING THIS CORRECTLY!
my $fn;
open ($fn, "< :raw", $path) or die "Sorry, unable to open the file: $tempfile. $!\n";
binmode($fn);
my @document = <$fn>;
close $fn;
my $len;
$len += length $_ for @document;
print"Content-type:application/x-download\n";
print"Content-disposition:attachment; filename=$file\n";
print"Content-length:$len\n\n";
binmode STDOUT;
print @document;
return;
} #END SUB send_file
####
my $in_fh;
open($in_fh, "<", $path)
|| die "$0: cannot open $path for reading: $!";
binmode($in_fh) || die "binmode failed";
print while <$in_fh>;
close($in_fh) || die "couldn't close $path: $!";
####
my $BUFSIZ = 64 * (2 ** 10);
my ($in_fh, $buffer);
open($in_fh, "<", $path)
|| die "$0: cannot open $path for reading: $!";
binmode($in_fh) || die "binmode failed";
while (read($in_fh, $buffer, $BUFSIZ)) {
unless (print $buffer) {
die "couldn't write to STDOUT: $!";
}
}
close($in_fh) || die "couldn't close $path: $!";