For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2006 > Downloading ZIP Files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Downloading ZIP Files
sjaworski@austin.rr.com

2006-02-21, 3:55 am

I searched many hours for this and thought it should be reposted for
perl users

$infile = "../albums/$ftp_path";
# Open the input file for reading
open IN, "< $infile"
or die "Can't open $infile: $!";
binmode IN;

# Get the file info
my @info = stat(IN);
my $length = $info[7];
my $blksize = $info[11] || 16384;


# Make sure that the output is written in
# binary mode and buffered
binmode STDOUT;
select STDOUT; $|=1;


# Send the HTTP header
print "Content-type: application/x-zip-compressed\n";
print "Content-Length: $length\n";
print "\n";


# Read each chunk of the input file
# and pass it to the browser
my $buffer;
while (!eof(IN)) {
read(IN, $buffer, $blksize);
print $buffer;
}
close IN;
exit 0;

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com