Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Downloading multiple zipped files

Posted on 2009-04-28
6
Medium Priority
?
260 Views
Last Modified: 2013-12-25
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

0
Comment
Question by:mph23
  • 3
  • 3
6 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24255339
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
 

Author Comment

by:mph23
ID: 24255536
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
 
LVL 39

Expert Comment

by:Adam314
ID: 24255662
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:mph23
ID: 24255915
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
 
LVL 39

Accepted Solution

by:
Adam314 earned 1000 total points
ID: 24283319
Do you have access to any of these on the server (not perl modules, binaries): gzip, zip, or tar?

0
 

Author Comment

by:mph23
ID: 24284455
We found a third party solution that works great but I'll definitely look into those you suggested for future reference.

Thanks!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question