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?

In reply to Reading CGI.pm file upload spools with Archive::Zip by OverlordQ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.