Downloading multiple zipped files

Posted on 2009-04-28
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/

#!/usr/bin/perl -wT


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="";

#chdir into appropriate directory

chdir ('../public_html/files/');




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;



Open in new window

Question by:mph23
    LVL 39

    Expert Comment

    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.

    Author Comment

    I realized (duh!) that I didn't have Archive::Zip loaded.

    I am on a linux server. Where should put the archive::zip files?
    LVL 39

    Expert Comment

    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


    Author Comment

    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?

    LVL 39

    Accepted Solution

    Do you have access to any of these on the server (not perl modules, binaries): gzip, zip, or tar?


    Author Comment

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


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now