#!/usr/bin/perl -wT
BEGIN {
open (STDERR, ">../public_html/error.txt");
}
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use Archive::Zip qw( :ERROR_CODES :CONSTANTS ) || die "Can't find Module";
my $zip = Archive::Zip->new();
my $q = new CGI;
my $i;
my $file1 = "p1.tif";
my $file2 = "p2.tif";
my $zip_file_name="MyFiles.zip";
#chdir into appropriate directory
chdir ('../public_html/files/');
$zip->addFile("$file1");
$zip->addFile("$file2");
die 'Cannot create $zip_file_name: $!\n' if $zip->writeToFileNamed("$zip_file_name") != AZ_OK;
#start downloading
$path = '../public_html/files/';
$filepath = "$path$zip_file_name";
my $size= -s $filepath;
my $buff;
print "Content-type: application/forced-download\r\n";
print "Content-Length: $size\r\n";
print "Content-disposition: attachment;filename=$zip_file_name\r\n\r\n";
open(FILE, "<$filepath") || die;
binmode FILE;
binmode STDOUT;
while (read FILE, $buff, 1024) {
print $buff;
}
close(FILE);
|