Downloading multiple zipped files

I'm trying to learn how to zip and download files. I found a solution on EE but can't get it to work. I am getting an Internal Server Error.

The tif files are in ../public_html/files.

I am new to perl/cgi so any assistance would be most appreciated.
I also searched for a self-extracting zip example on cpan but couldn't figure out how to view examples (i.e., examples/selfex.pl).

Thanks
#!/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);

Open in new window

mph23Asked:
Who is Participating?
 
Adam314Connect With a Mentor Commented:
Do you have access to any of these on the server (not perl modules, binaries): gzip, zip, or tar?

0
 
Adam314Commented:
Have you looked in your log file?  It'll give you more details on the actual error.

If you are running apache on a unix-type server, this is typically /var/log/apache2/error.log, but could be different depending on your setup.
0
 
mph23Author Commented:
I realized (duh!) that I didn't have Archive::Zip loaded.

I am on a linux server. Where should put the archive::zip files?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Adam314Commented:
If you have root access, you should install them into your default path.  If you use the cpan module to do the installation, it'll take care of everything - including installing any necessary dependencies.

As root, type:
    cpan Archive::Zip

0
 
mph23Author Commented:
I am on a godaddy hosted account and I just called them because archive::zip isn't one of the installed modules under their Perl/CGI Admin and they said I can't install it myself.

Is there any other way to zip files?

0
 
mph23Author Commented:
We found a third party solution that works great but I'll definitely look into those you suggested for future reference.

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.