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

Discussion in 'Perl Misc' started by diegodelima.poa@gmail.com, Jan 4, 2007.

  1. Guest

    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
    , Jan 4, 2007
    #1
    1. Advertising

  2. Guest

    wrote:
    > 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.
    }


    --
    The best way to get a good answer is to ask a good question.
    David Filmer (http://DavidFilmer.com)
    , Jan 4, 2007
    #2
    1. Advertising

  3. J. Gleixner Guest

    wrote:
    > 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.
    J. Gleixner, Jan 4, 2007
    #3
  4. wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jan 4, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. homecurr
    Replies:
    1
    Views:
    2,412
    Murray
    Jul 23, 2004
  2. Geathaa
    Replies:
    2
    Views:
    680
    Geathaa
    Jul 30, 2003
  3. ectoplasm
    Replies:
    12
    Views:
    623
    Zorro
    Jul 28, 2005
  4. shumsta
    Replies:
    1
    Views:
    244
    Fabian Pilkowski
    Jul 22, 2005
  5. Dave
    Replies:
    5
    Views:
    618
    John Bokma
    Apr 26, 2011
Loading...

Share This Page