Greetings monks! First, I'll start off with the code, so you can tell me if I'm even going in the right direction. Then I'll tell you my problem.
#!/usr/bin/perl -w
use strict;
use CGI;
use Archive::Zip;
##Initialize CGI
my $cgi = new CGI;
print $cgi->header();
##Ohnoes start over
unless( $cgi->param('step') ) {
starthtml();
print <<HTML;
<font face="Verdana, Arial, Helvetica, sans-serif">Please enter th
+e number of files you need to upload:
HTML
##FormStuff
print $cgi->start_form;
print $cgi->textfield('nfiles');
print $cgi->hidden('step','2');
print $cgi->submit;
print $cgi->end_form;
##Finish off Teh HTML
print <<HTML;
</p></div>
</body>
</html>
HTML
}
if ( $cgi->param('step') == '2' ) {
##Clear the step num
$cgi->delete('step');
starthtml();
##Start Form and loop through to create number of upload fields we
+ need
print $cgi->start_form;
for(my $i = 1; $i <= $cgi->param('nfiles');$i++) {
print $cgi->filefield(-name=>"file$i"),"<br />\n";
}
##Next step, also send number of files again
print $cgi->hidden('step','3');
print $cgi->hidden('nfiles',$cgi->param('nfiles'));
print $cgi->submit();
print $cgi->end_form();
} elsif ( $cgi->param('step') == '3' ) {
##Here is teh problem##
my @files;
for (my $i = 1; $i <= $cgi->param('nfiles'); $i++) {
my $filename = $cgi->param("file$i");
my $upload_filehandle = $cgi->upload("file$i"); ## Probably no
+t the best way to do that but ohwell
###
### Archive::Zip Processing here
###
}
sub starthtml {
print <<START;
<html>
<head>
<title>Update Tool</title>
</head>
<body bgcolor="#006633">
<div align="center">
<p><font size="+2" face="Verdana, Arial, Helvetica, sans-serif
+">Update Tool</font><br />
<br />
<br />
START
}
I read over the CGI.pm docs and calling the
upload() method will return the filehandle to the temporary file that CGI.pm created. But looking over
Archive::Zip, it looks as if it wants the name of the zip in the
new() constructor. Are there any
CGI.pm calls I'm missing that I can get the name of the file? Or will I have to write to disk ala:
open (OUTFILE,">>/tmp/file");
binmode(OUTFILE);
while ($bytesread=read($filename,$buffer,1024)) {
print OUTFILE $buffer;
}
then read the file with
Archive::Zip, process what needs done, then unlink?