sub unzip_and_save { # return a reference to scalar containing index.html # and a reference to array containing .pdf names my ( $zipFileName ) = @_; use Archive::Zip; my $zip = Archive::Zip->new; my $status = $zip->read( $zipFileName ); if ($status) { error( $cgi, $cgi->p("There is an error in your zip file. Please ensure that the file you are uploading is a valid archive and try again.") ); } my ($member,$extractedFile, @pdfs, $index); foreach $member ($zip->memberNames()) { push @pdfs, $member if $member =~ /\.pdf$/i; # Add error checking to check for more than one index $index = $member if $member =~ /index\.html?$/; $extractedFile = UPLDTMPDIR . '\\' . $member; # only allow them to extract files with pdf or html extensions if ( $member =~ /\.(pdf|html?)$/i ) { my $status = $zip->extractMember($member,$extractedFile); if ( $status ) { error( $cgi, $cgi->p( "Error code: $status" ) ) if $status; } } } if ( ! defined $index ) { error( $cgi, $cgi->p("No index.html file found in zip archive.")); } elsif ( ! @pdfs ) { error( $cgi, $cgi->p("No pdfs found in zip archive")); } return ( $index, \@pdfs ); }