Hi -
I am trying to generate fairly large zip archives "on the fly." I'd like for the user to be able to download a single zip file containing thousands of files.
I have been able to do this successfully, using two methods. The problem with the
first method is that the users get timeout errors in their browsers (my guess is that "addTreeMatching" takes too long - there are thousands of files). The problem with the
second method is that when you go to unarchive the zip file, only the first file appears (I suspect that this is a problem with the central directory). Any help would be greatly appreciated! Ideally, I'd be able to use some form of the second method, as that gives me the flexibility of renaming the files prior to archiving them.
First Method
use Archive::Zip;
my $zip = Archive::Zip->new(); # new instance
$zip->addTreeMatching( "/$NewHomePath/Results/$InvoiceNumber",
+ "$InvoiceNumber", '\.(ab1$|seq$)' );
print "Content-Type:application/zip\n";
print "Content-Disposition:attachment;filename=$FileNameToWrit
+e\n\n";
$zip->writeToFileHandle(*STDOUT);
Second Method
use Archive::Zip;
my $zip = Archive::Zip->new(); # new instance
chdir("/$NewHomePath/Results");
@files = (<$InvoiceNumber/*.ab1>); # files to store
@filesA = (<$InvoiceNumber/*.seq>); # files to store
push (@files,@filesA);
#PRINT HEADER
print "Content-Type:application/zip\n";
print "Content-Disposition:attachment;filename=$FileNameToWrit
+e\n\n";
#NOW PRINT TO STDOUT
foreach $file (@files) {
if ($DLWOSC eq "checked"){
$TranslatedName=(split('/',$file))[-1];
$TranslatedName=~s/\;/\_/g;
$zip->addFile($file,$TranslatedName); # add files
$zip->writeToFileHandle(*STDOUT);
}else{
$zip->addFile($file);
$zip->writeToFileHandle(*STDOUT);
}
}