Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: CGI, uploading multiple files

by huck (Prior)
on Mar 13, 2017 at 21:55 UTC ( #1184484=note: print w/replies, xml ) Need Help??


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

eval { open (OUTFILE,">$upload_folder/$upload") or die $!;; binmode OUTFILE; while (<$upload_file>) { print OUTFILE; } close OUTFILE; }; print 'error:'.$@.'<br>' if $@;
the point made by pojabout use CGI::Carp 'fatalsToBrowser'; may serve to do the same thing. Or it may identify another error

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

my @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/>"; } }
see http://search.cpan.org/~leejo/CGI-4.35/lib/CGI.pod#Processing_a_file_upload_field

you may also be interested in

my $type = $q->uploadInfo( $upload_file )->{'Content-Type'};
To determine if you need binmode and should use read, or if you dont want binmode and can use <$upload_file>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1184484]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2021-10-17 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (72 votes). Check out past polls.

    Notices?