Hi.. i would like to know how to handle multiple upload files with the cgi module in perl script..
With single file, -
my $my_cgi new CGI;
-
my $upload_filehandle = cgi ->upload('file1');
-
my $filename = $cgi->param('file1');
-
$filename =~ s/.*[\/\\](.*)/$1/;
-
if ($upload_filehandle) {
-
open(FILE1, ">$upload_dir/$filename") || print("Could not open file!");
-
binmode FILE1;
-
while (<$upload_filehandle>) {
-
print FILE1 ;
-
}
-
close FILE1;
-
For multiple files, how to determine how many files are there? if the filename are file1, file2, file3, file4......
6 13128 Don't use different names for the file upload fields, use the same name for all of them. Then read in the value of the file fields in list context (array) instead of scalar context:
my @upload_filehandles = cgi ->upload('fileup');
Don't use different names for the file upload fields, use the same name for all of them. Then read in the value of the file fields in list context (array) instead of scalar context:
my @upload_filehandles = cgi ->upload('fileup');
Hi.. thanks for the reply..
I know that option is available.. but i do not want to have the same filename cos i want to carry out some operations later.
You should still be able to do anything you wanted to even if the file fields are all the same name. But if you wanted to use different names you could hard code them into the script if you know what the names will be.
my @file_upload_fields = qw(file1 file2 file3 file4 file5);
foreach my $fields (@file_upload_fields) {
....
}
You should still be able to do anything you wanted to even if the file fields are all the same name. But if you wanted to use different names you could hard code them into the script if you know what the names will be.
my @file_upload_fields = qw(file1 file2 file3 file4 file5);
foreach my $fields (@file_upload_fields) {
....
}
Hi thanks for the reply...
Anyway i managed to solve the problem using some loops and checking.. thanks
Dear friends, -
my $respid = $q->param('rid');
-
my ($data, $n, $size);
-
if ($q->param('cmd') eq 'upload_img'){
-
my @file = ();
-
my @files = $q->param('file');
-
-
foreach (@files){
-
push @file, $_ if length $_ > 0;
-
}
-
-
my $r = ();
-
foreach my $f (@file){
-
while (($n = read $f, $data, 10000000, $size) != 0) {
-
$r = $data;
-
}
-
-
# create record in resp_images to have an unique image id
-
my $query = "INSERT INTO IMAGES2 (RespondentID, UserID, Created, Completed)".
-
"VALUES ($respid, '1', NOW(), 1)";
-
# insert
-
$dbh->do ($query);
-
-
# set imageid into cookie message
-
my $image_id = $dbh->{'mysql_insertid'};
-
-
if ($image_id) {
-
my $query = "UPDATE ".IMAGES2.
-
" SET Image=".$dbh->quote($r)." WHERE ImageID=".$image_id;
-
$dbh->do($query);
-
-
}
-
-
}
-
-
}
-
-
print $q->startform(-name => 'form',
-
-method => 'POST',
-
-action => 'upload_img',
-
-enctype => 'multipart/form-data'
-
);
-
print "<table border=0 style=\"color:black;\" valign=top cellspacing=0 cellpadding=0 width=35%>";
-
print "<tr>";
-
print "<td style=\"color:black;\" colspan=3 height=\"70\">";
-
for (my $i=0; $i<5; $i++){
-
print " Resim Seç : </b><input type=\"file\" name=\"file\" /><br><br>";
-
}
-
print $q->button
-
(-name => 'update',
-
-value => "Gönder",
-
-style => $RS{BUTTON_STYLE}."width:75;",
-
-onClick => "cmd.value='upload_img';this.form.submit();"
-
);
-
print "</center></td></tr>";
-
print &hidden_param('cmd' , '');
-
print &hidden_param('rid' , $q->param('rid'));
-
print $q->endform;
-
see you soon...
Next time, legolas188, please surround your code in code tags so we don't have to.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics
by: 3A Web Hosting |
last post by:
Hi
Is it possible to perform multiple file uploads via a form? It's no
problem uploading single files but I want to be able to highlight a
group of files and upload them all in one go. My...
|
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...
|
by: Sundar |
last post by:
Hi,
I am working on ASP.Net. My requirement is that I want
to Upload Multiple Files to the Server. I need to have
ONLY ONE FILE UPLOAD CONTROL in my page. I SHOULD NOT
SUBMIT THE PAGE FOR EACH...
|
by: Jason |
last post by:
I have a potential need to upload multiple PDF legal documents. Is it
possible to attach more than one file per upload?
|
by: crowl |
last post by:
Hi there,
I am looking for a component allowing me uploading multiple files by my
asp page. I have found several components achieving this by require a
<input type="file" name="FileX"> field for...
|
by: dann2 |
last post by:
hello,
i try to upload in an access db two pictures at the same time. i use the adjusted sample code from persits. it looks like this:
...
'<%
' Create an instance of AspUpload object
'Set...
|
by: der_grobi |
last post by:
That is the Problem:
I have an ASP.NET Webapplicatipon where I can upload single files to
the Server.
That works fine. But now, I want to Upload multiple files. I know the
path of the files, i...
|
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...
|
by: MoroccoIT |
last post by:
Greetings -
I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |