473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

upload multiple files with perl

Hello everyone,

I am new to Perl, and stuck with file uploading issue.

My Html is this,

Expand|Select|Wrap|Line Numbers
  1. <form enctype="multipart/form-data" method=post action="/cgi-bin/upload/mfile.pl">
  2. <input type=file name=file size="30"><br />
  3. <input type=file name=file size="30"><br />
  4. <input type=file name=file size="30"><br />
  5. <input type="submit" value="Upload Image!">
  6. </form>
My perl

Expand|Select|Wrap|Line Numbers
  1. my @upload_filehandles = $query ->upload('file'); 
  2. my $arrLen = scalar @upload_filehandles; 
  3. logit("The size of array is $arrLen");
I am expecting a array of 3 upload_filehandles, but the size of array is 1 only when it print out

How can i upload multiple files with same named field?


Many thanks
Aug 3 '10 #1
3 4575
chaarmann
785 Expert 512MB
If you upload a file then you can't access the data the same way you access the values of option-boxes or text-boxes or URL-parameters. You must handle multipart content and you will get binary data that you will need to read from the input stream byte by byte yourself through looping.

Second, if you use the same name or id on html-elements multiple times, you will either get an array of their values back, or only the first value. Even if you get an array with filenames back, you can't determine which binary data inside the input stream then corresponds to what name.

So uploading many files at once doesn't work the way you want it.
Either stick with it and change your interface to the way goggle-mail is uploading attachments. (Here you can only upload files one by one, but then returning back to the webpage where it shows a list of uploaded files so far before committing the mail).

Or maybe this trick will help:
Put many forms inside one webpage. Each form has a single file-input box. Then make a button that, when pressed, calls a javascript to executes form.submit() on all forms. But I fear you may not like it in this way when there are opening many windows to ask for selecting the files one by one
Aug 3 '10 #2
Thanks chaarmann,

there is link at http://bytes.com/topic/perl/answers/...les-upload-cgi talking about using same file name for multiple files upload. it seems like that is possible. but it just doesn't work for me.
Aug 3 '10 #3
chaarmann
785 Expert 512MB
Dear Dija002,

I read the link. But the Autor "KevinADC" does not tell us why you should use the same file name. But if you look at the fileUpload-HTML form of another solution that works fine (see http://www.planet-source-code.com/UR...!6/anyname.htm), they are using different names! (So maybe it's a browser compatibility issue???)

By the way, I analyzed the last source code given by "legolas188" in the thread you mentioned. There he is getting only the file names as an array and then trying to read these files from disk (and not from the browser's data stream). There must be other code which does the upload of the file but which is not listed here. So no wonder it doesn't work with you.

I suggest that you try the code mentioned in the link above. I analyzed it and it seems to work (although it's very cryptical and needs a rewrite. It's missing meaningful variable names and comments inside). I haven't tried it yet, but I couldn't see any error and it looks the same way I have done it in C++ once, parsing the input stream from the browser.
Aug 4 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
1
by: makthar | last post by:
Hi Everyone: I want to make a page for the users to be able to upload multiple files to the server. Presently I use a html file field but it allows selection of a single file only. Does any...
1
by: Susan | last post by:
Is it possible to use PHP with VBScript or JavaScript to upload multiple files. I'd like to automate the upload of a complete directory (not using FTP). I don't need a common form with several...
3
by: JFB | last post by:
Hi All, It's a way to upload multiple files on a web site using vb.net 2005? I see the uploadFile tool, but it's only for one file. Any ideas, examples, links??? Tks in advance JFB
0
by: deepaks85 | last post by:
Dear Friends, I am trying to upload multiple files. But I can't find why it is not working fine. Here is the code......... numfile.php <form method="POST" action="fileupload.php"> <p...
0
by: deepaks85 | last post by:
Dear Friends, I am trying to upload multiple files. But I can't find why it is not working fine. Here is the code......... numfile.php <form method="POST" action="fileupload.php"> <p...
3
by: deepaks85 | last post by:
Dear Friends, I have post this query 4 days ago......but no one replied me..... I request you all to please help me on this.............. I am trying to upload multiple files. But I can't...
10
by: Sebarry | last post by:
Hi, I'm using the code at http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/ to upload multiple files with a single file element. It works fine...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
0
AnuSumesh
by: AnuSumesh | last post by:
Hi We have an application where we can upload file from client machine to any shared device on the network. Now our requirement is to upload multiple files over the network. e.g. to path...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.