Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

and i found the MAGIC SPELL 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="" 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 ###### +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;
$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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2021-10-22 03:08 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.