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!
Result#!/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;
$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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |