in reply to CGI, uploading multiple files
Have you checked the error.log of your server to see if there are any error conditions raised while it ran?
The only way i can see it not returning the print "<p><b>Name</b> -- $name<br><b>Email</b> -- $email<br><b>Comments</b> -- $comments<br>"; contents is if the cgi process terminated wit an error before reaching that point, like dieing because it cannot open the file.
To catch what would otherwise be a terminal error you can wrap the code in an eval block like so
the point made by pojabout use CGI::Carp 'fatalsToBrowser'; may serve to do the same thing. Or it may identify another erroreval { open (OUTFILE,">$upload_folder/$upload") or die $!;; binmode OUTFILE; while (<$upload_file>) { print OUTFILE; } close OUTFILE; }; print 'error:'.$@.'<br>' if $@;
ps, what do you think should be in $upload_file? what parm has the same name as of one of the files to be uploaded, not the value, its name.
consider
see http://search.cpan.org/~leejo/CGI-4.35/lib/CGI.pod#Processing_a_file_upload_fieldmy @files = $q->param('multi_files'); my @io_handles=$q->upload('multi_files'); foreach my $upload(@files){ print "Upload this please -- $upload<br>"; my $upload_file = shift @io_handles; if ($upload_file){ eval { open (OUTFILE,">$upload_folder/$upload") or die $!;; binmode OUTFILE; while ( my $bytesread = $upload_file->read($buffer,1024) ) { print OUTFILE $buffer; } close OUTFILE; }; print 'error:'.$@.'<br>' if $@; } else { print "<b>Guess it's broken</b><br/>"; } }
you may also be interested in
To determine if you need binmode and should use read, or if you dont want binmode and can use <$upload_file>my $type = $q->uploadInfo( $upload_file )->{'Content-Type'};
|
|---|