sub SendFile { my $cgi = shift || CGI->new; my $file = shift or die "What file to send?!"; my $filename = shift || 'filename'; my $mimetype = shift || 'application/octet-stream'; open my($fh),'<:raw', $file or die "Can't read ($file): $!\n$^E\n "; binmode STDOUT; print $cgi->header( -type => $mimetype, -attachment => $filename, -Content_length => -s $fh, ); # print $_ while readline $fh; local $/; ## slurp mode print readline($fh); close $fh; close STDOUT; }