Well i found out what was in the parts, PERLIO filehandles

and i found the MAGIC SPELL http://stackoverflow.com/questions/3196783/perl-file-upload-cant-init-filehandle File upload forms need to specify enctype="multipart/form-data". ----- Sinan Ünür

Ubuntu tested code (well at least with $tostdout=1).

AND Notice how the filename starts with a folder!

#!/usr/bin/perl use strict; use warnings; use CGI; use Data::Dumper; use HTML::Entities qw/encode_entities/; my $q = CGI->new(); print $q->header; unless ($q->param('multi_files')) { print ' <html> <head> <title>Stupid Test Site</title> </head> <body> <h1>This is a test</h1> <form action="multiupload.pl" enctype="multipart/form-data". +method="POST"> Your Name: <input type="text" name="name"><br> Email Address: <input type="text" name="email"><br> Select PO folder: <input name="multi_files" type="file" we +bkitdirectory multiple /><br/> Comments:<br> <textarea name="comments" rows="5" cols="60"></textarea><b +r> <input type="submit" value="Send"> </form> </body> </html> '; exit; } my $upload_folder = '/var/www/html/uploads'; my $name = $q->param('name'); my $email = $q->param('email'); my $comments = $q->param('comments'); my @files = $q->param('multi_files'); my $tostdout=1; ###### see ###### http://stackoverflow.com/questions/3196783/perl-file-upload-can +t-init-filehandle ###### File upload forms need to specify enctype="multipart/form-data" +. ----- Sinan Ünür my @io_handles=$q->upload('multi_files'); print '<pre>'; print Dumper(\@files); print Dumper(\@io_handles); print '</pre>'; print '<br>step0'; for my $upload (@files){ print "<br>Upload this please -- $upload<br>"; if ($upload){ eval { if ($tostdout) { print '<pre>' ; while ( my $buffer = <$upload>) { print STDOUT encode_entities($buffer); } # while print '</pre>' ; } # tostdout else { open (OUTFILE,">$upload_folder/$upload") or die $!;; binmode OUTFILE; while ( my $buffer = <$upload>) { print OUTFILE $buffer; } # while close OUTFILE; } # notstdout }; # eval print 'error:'.$@.'<br>' if $@; } # upload else { print "<br><b>Guess it's broken</b><br/>"; } # else } # $upload print "<p><b>Name</b> -- $name<br><b>Email</b> -- $email<br><b>Comment +s</b> -- $comments<br>"; print $q->end_html;
Result
$VAR1 = [ bless( \*{'Fh::fh00001multiuploads/a.txt'}, 'Fh' ), bless( \*{'Fh::fh00002multiuploads/Copy of a.txt'}, 'Fh' ), bless( \*{'Fh::fh00003multiuploads/Copy (2) of a.txt'}, 'Fh' + ) ]; $VAR1 = [ bless( \*{'Fh::fh00001multiuploads/a.txt'}, 'Fh' ), bless( \*{'Fh::fh00002multiuploads/Copy of a.txt'}, 'Fh' ), bless( \*{'Fh::fh00003multiuploads/Copy (2) of a.txt'}, 'Fh' + ) ]; step0 Upload this please -- multiuploads/a.txt this is a.txt Upload this please -- multiuploads/Copy of a.txt this is a.txt Upload this please -- multiuploads/Copy (2) of a.txt this is a.txt Name -- a Email -- b Comments -- ok


In reply to Re: CGI, uploading multiple files by huck
in thread CGI, uploading multiple files by edimusrex

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.