CGI.pm - Upload multiple files using the same query param

  • Thread starter diegodelima.poa
  • Start date
D

diegodelima.poa

I need to upload multiple files using inputs with the same name, like
an array of files.

I know CGI.pm understands pretty well any number of inputs of type text
with the same name, and i've been using it for a while. This time I
need the same behavior with uploading files.

Is this possible?

I know many will advice me to use file1, file2, fileN, but I have some
platform specific reasons that would meke it lots easier to me if using
the same param names where possible.

Thanks!

Diego de Lima
 
U

usenet

I need to upload multiple files using inputs with the same name, like
an array of files.

No problem. For example:

for (1..5) {
print p( filefield(-name=>'upload',-size=>60) );
}

That prints out five upload fields with the same parameter name, and
the parameter will act like an ordinary array when you go to process
it:

foreach my $file( param('upload') ) {
# upload the file and do whatever.
}
 
J

J. Gleixner

I need to upload multiple files using inputs with the same name, like
an array of files.

I know CGI.pm understands pretty well any number of inputs of type text
with the same name, and i've been using it for a while. This time I
need the same behavior with uploading files.

Is this possible?

I know many will advice me to use file1, file2, fileN, but I have some
platform specific reasons that would meke it lots easier to me if using
the same param names where possible.

How would the server know anything about the files on the client? The
server only knows what is sent to it, so you either upload multiple
files, using multiple input type="file" elements, or you tar/zip
them on the client and send one, then untar/unzip on the server.
Another choice is to use JavaScript to automate it, many are
available by searching the Internet.
 
G

Gunnar Hjalmarsson

I need to upload multiple files using inputs with the same name, like
an array of files.

I know CGI.pm understands pretty well any number of inputs of type text
with the same name, and i've been using it for a while. This time I
need the same behavior with uploading files.

Is this possible?

Yes. One easy way to do it is to make use of the CPAN module
CGI::UploadEasy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top