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); } }

In reply to Creating Zip Archives on the fly by fulmar2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.