in reply to Reading CGI.pm file upload spools with Archive::Zip

$zip = Archive::Zip->new(...);
is the same as
$zip = Archive::Zip->new();
my $status = $zip->read(...);
$zip = undef unless ($status == AZ_OK);
so use
$zip = Archive::Zip->new();
my $status = $zip->readFromFileHandle($upload_filehandle);
$zip = undef unless ($status == AZ_OK);

Untested.

Update: You know what, it looks like read() and (therefore) new() accept a filehandle as an alternative to a file name. So, $zip = Archive::Zip->new($upload_filehandle); should work fine.

Replies are listed 'Best First'.
Re^2: Reading CGI.pm file upload spools with Archive::Zip
by OverlordQ (Hermit) on Sep 01, 2004 at 20:31 UTC
    Hmmm I tried your first code, but i got this:
    print "On file: $i\n<br>"; my $filename = $cgi->param("file1") or print "Cannot do that: $!\n"; print "Uploading . . ."; my $upload_filehandle = $cgi->upload("file$i") or print "cant upload: +$!\n"; print "done<br>\n"; print "Making zip . . ."; my $zip = Archive::Zip->new() or print "Canot make zippah: $!\n"; print "done<br>\n"; print "Reading Zip . . . "; my $status = $zip->readFromFilehandle($upload_filehandle); print "done<br>\n"; print "Mah Statuhs: $status\n"; $zip = undef unless ($status eq 'AZ_OK'); if(defined($zip)) { print $zip->members(); } else { print "Ooops something happened: $!\n"; }
    But this is what I get for output:
    Mungeing!
    On file: 1
    Uploading . . .done
    Making zip . . .done
    Reading Zip . . .
    Dunno what's up there :-(
      I really do not have a explination, and if someone has one I would like to know. You have to make a reference of the dereferenced file handler object. In your case you read line should look like this.

      my $status = $zip->readFromFilehandle(\$$upload_filehandle);

      Here a segement of code that I used to get this working...

      my $fh = $c->upload('zip');
      my $zip = Archive::Zip->new();
      $zip->read(\$$fh);

      my @members = $zip->members();

      foreach my $member (@members){
      my $filename = $member->fileName();
      print "$filename\n";
      }