in reply to Downloading a file
Is it possible that you printed a header before this function was called?#!/usr/bin/perl use strict; use warnings; my $filename = 'pm.tgz'; my $filesize = -s $filename; # $filepath is the directory # $filename is the name of the file # print full header print "Content-disposition: inline; filename=$filename\n"; print "Content-Length: $filesize\n"; print "Content-Type: application/octet-stream\n\n"; # open in binmode open(READ,,'<',$filename) || die; binmode READ; # stream it out binmode binmode STDOUT; while (<READ>) { print; } close(READ); # should always return true return(1);
I would recommend the following minor changes :
#!/usr/bin/perl use strict; use warnings; my $filename = 'pm.tgz'; my $filesize = -s $filename; # $filepath is the directory # $filename is the name of the file # print full header print "Content-disposition: inline; filename=$filename\n"; print "Content-Length: $filesize\n"; print "Content-Type: application/octet-stream\n\n"; # open in binmode open my $read,'<',$filename or die "Failed to read $filename - $!"; + binmode $read; # stream it out binmode binmode STDOUT; while (<$read>) { print; } # should always return true return(1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Downloading a file
by bart (Canon) on Sep 09, 2006 at 06:34 UTC |