OverlordQ has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 }
open (OUTFILE,">>/tmp/file"); binmode(OUTFILE); while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading CGI.pm file upload spools with Archive::Zip
by ikegami (Patriarch) on Sep 01, 2004 at 19:43 UTC | |
by OverlordQ (Hermit) on Sep 01, 2004 at 20:31 UTC | |
by siroskey (Initiate) on Sep 16, 2004 at 01:47 UTC |