I'm trying to write a small cgi app that takes an uploaded zip file,
extracts the contents and does some operations on the included files.
Following is a cut down version of my attempts to understand how to
manipulate a zip file.  It doesn't work (surprise, surprise!)  It
creates an empty file with the correct name, but then dies.  It also
won't work using #!/usr/bin/perl -wT, but I haven't tried to sort that
yet.  Can anyone please point me in the right direction?

HTML form:
<html>
<head>
<title>Zip test form</title>
</head>
<body>
<form action="/cgi-bin/zip_example" method="post"
ENCTYPE="multipart/form-data">
Zip file: <INPUT TYPE="file" NAME="zip_file"/><br/>
<INPUT TYPE="submit" NAME="submit" VALUE="Upload"/>
</form>
</body>
</html>

Perl cgi:
#!/usr/bin/perl -w

use CGI;
use strict;
use Fatal qw /open mkdir chdir /;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Archive::Zip qw( :ERROR_CODES ) ;

my @results;
my $working_dir = "/usr/local/example";
my $upload = new CGI;
# form INPUT fields expected:
#   TYPE="file" NAME="zip_file"

my $upload_hash_ref = $upload->Vars;
my $upload_hash_ref= $upload->Vars;
$upload_hash_ref->{'zip_file'}=~ s/.*[\/\\](.*)/$1/;

my $zip = Archive::Zip->new();
# I don't think this line does what I want!
$zip->read($upload->upload("zip_file"));
open ZIPINSTANCE, "> $working_dir/$upload_hash_ref->{'zip_file'}";
# Save the Zip file to disk
unless ( $zip->writeToFileNamed("ZIPINSTANCE") == AZ_OK ) {
        die 'Here I lay, mortally struck';
}
push (@results, "wrote zip file to disk");

print $upload->header;
print $upload->start_html(-title=>"Zip test results");
print "<h2>Results</h2>";
foreach (@results){
        print "<p>$_</p>";
}
print $upload->end_html;



Thanks,
Tim Bowden


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to