sub get_filename
{
my ($file) = @_;
$file =~ s!\\!/!g; # chnage windows path as needed
my @parts = split /\//, $file;
return pop @parts;
}
sub send_file_to_browser
{
my ($file) = @_;
my $name = get_filename($file);
$name =~ s! !%20!g;
$name ||= "[N/A]";
print "Content-Disposition: inline; filename=\"$name\"\n";
print "Content-Type: application/octet-stream\n\n";
send_binaryfile_to_browser($file);
1;
}
sub send_binaryfile_to_browser
{
my ($file) = @_;
binmode STDOUT;
if(open(FILE, "< $file"))
{
binmode FILE;
while(<FILE>) { print $_; }
close FILE;
}
}