Uploading multiple files

  • Thread starter Melissa McGehee
  • Start date
M

Melissa McGehee

Hi there! Been a while...3 years... but I'm back!

I have a script that uploads ONE user file. But I want to upload two. This
seems like a simple question...but in the newsgroup messages downloaded, I
cannot find anything that matches.

Please advise what I can do to upload multiple files. I have a section
commented out below that was SUPPOSED to allow the second file to
upload...but never worked. ALL SUGGESTIONS WELCOMED!

Many thanks! (and it's great to be back...)

~Melissa

---------------------------------

use CGI qw:)standard);
$query = new CGI;

########################################################################
# Breaks down the name-value pairs.
########################################################################

foreach $key (sort {$a <=> $b} $query->param()) {
$CAT =$query->param('CAT');
$SKU =$query->param('SKU');
$MF =$query->param('MF');
$ITEM =$query->param('ITEM');
$L =$query->param('L');
$W =$query->param('W');
$H =$query->param('H');
$PRICE =$query->param('PRICE');
$DES =$query->param('DES');
$RSKU1 =$query->param('RSKU1');
$RSKU2 =$query->param('RSKU2');
$RSKU3 =$query->param('RSKU3');
$RSKU4 =$query->param('RSKU4');
$RSKU5 =$query->param('RSKU5');
$RSKU6 =$query->param('RSKU6');
$RSKU7 =$query->param('RSKU7');
$RSKU8 =$query->param('RSKU8');
$RSKU9 =$query->param('RSKU9');
$RSKU10 =$query->param('RSKU10');
$SUBITEM1 =$query->param('SUBITEM1');
$SUBDIMS1 =$query->param('SUBDIMS1');
$SUBPRICE1 =$query->param('SUBPRICE1');
$SUBITEM2 =$query->param('SUBITEM2');
$SUBDIMS2 =$query->param('SUBDIMS2');
$SUBPRICE2 =$query->param('SUBPRICE2');
$SUBITEM3 =$query->param('SUBITEM3');
$SUBDIMS3 =$query->param('SUBDIMS3');
$SUBPRICE3 =$query->param('SUBPRICE3');


next if ($key =~ /^\s*$/);
next if ($query->param($key) =~ /^\s*$/);
next if ($key !~ /^IMG$/);
# foreach $key {
# $Number = $1;

if ($query->param($key) =~ /([^\/\\]+)$/) {
$Filename = $1;
$Filename =~ s/^\.+//;
$File_Handle = $query->param($key);

}


open(LOG, ">../$CAT/$Filename") || &ErrorMessage;

undef $BytesRead;
undef $Buffer;

while ($Bytes = read($File_Handle,$Buffer,1024)) {
$BytesRead += $Bytes;
print LOG $Buffer;
}

push(@Files_Written, "../$CAT/$Filename");
$TOTAL_BYTES += $BytesRead;
$Confirmation{$File_Handle} = $BytesRead;

close($File_Handle);
close(LOG);

chmod (0777, "../$CAT/$Filename");

#########################################################
#
# next if ($key =~ /^\s*$/);
# next if ($query->param($key) =~ /^\s*$/);
# next if ($key !~ /^THUMB$/);
# $Number = $1;
#
# if ($query->param($key) =~ /([^\/\\]+)$/) {
# $Filename2 = $1;
# $Filename2 =~ s/^\.+//;
# $File_Handle2 = $query->param($key);
#
# }
#
#
# open(LOG, ">../../PDC/$CAT/$Filename2") || &ErrorMessage2;
#
# undef $BytesRead;
# undef $Buffer;
#
# while ($Bytes = read($File_Handle2,$Buffer,1024)) {
# $BytesRead += $Bytes;
# print LOG $Buffer;
# }
#
# push(@Files_Written2, "../../PDC/$CAT/$Filename2");
# $TOTAL_BYTES += $BytesRead;
# $Confirmation{$File_Handle2} = $BytesRead;
#
# close($File_Handle2);
# close(LOG);
#
# chmod (0777, "../../PDC/$CAT/$Filename2");
#
#
#########################################################

$file = $SKU . ".txt";
$IMG2 = $Filename;
# $TIMG2 = $Filename2;

open(LOG, ">../$CAT/$file") || &ErrorMessage;
chmod(0777, "../$CAT/$file");
print LOG "$CAT\n";
print LOG "$SKU\n";
print LOG "$MF\n";
print LOG "$ITEM\n";
print LOG "$L\n";
print LOG "$W\n";
print LOG "$H\n";
print LOG "$PRICE\n";
print LOG "$IMG2\n";
# print LOG "$TIMG2\n";
print LOG "$DES\n";
print LOG "$RSKU1\n";
print LOG "$RSKU2\n";
print LOG "$RSKU3\n";
print LOG "$RSKU4\n";
print LOG "$RSKU5\n";
print LOG "$RSKU6\n";
print LOG "$RSKU7\n";
print LOG "$RSKU8\n";
print LOG "$RSKU9\n";
print LOG "$RSKU10\n";
print LOG "$SUBITEM1\n";
print LOG "$SUBDIMS1\n";
print LOG "$SUBPRICE1\n";
print LOG "$SUBITEM2\n";
print LOG "$SUBDIMS2\n";
print LOG "$SUBPRICE2\n";
print LOG "$SUBITEM3\n";
print LOG "$SUBDIMS3\n";
print LOG "$SUBPRICE3\n";
close(LOG);

print <<HTML_CODE;
 
W

William Herrera

Hi there! Been a while...3 years... but I'm back!

I have a script that uploads ONE user file. But I want to upload two. This
seems like a simple question...but in the newsgroup messages downloaded, I
cannot find anything that matches.

Please advise what I can do to upload multiple files. I have a section
commented out below that was SUPPOSED to allow the second file to
upload...but never worked. ALL SUGGESTIONS WELCOMED!

Many thanks! (and it's great to be back...)

..............
next if ($key =~ /^\s*$/);
next if ($query->param($key) =~ /^\s*$/);
next if ($key !~ /^IMG$/);
# foreach $key {
# $Number = $1;

if ($query->param($key) =~ /([^\/\\]+)$/) {
$Filename = $1;
$Filename =~ s/^\.+//;
$File_Handle = $query->param($key);

}


open(LOG, ">../$CAT/$Filename") || &ErrorMessage;

undef $BytesRead;
undef $Buffer;

while ($Bytes = read($File_Handle,$Buffer,1024)) {
$BytesRead += $Bytes;
print LOG $Buffer;
}

push(@Files_Written, "../$CAT/$Filename");
$TOTAL_BYTES += $BytesRead;
$Confirmation{$File_Handle} = $BytesRead;

close($File_Handle);
close(LOG);

chmod (0777, "../$CAT/$Filename");

#########################################################
#
# next if ($key =~ /^\s*$/);
# next if ($query->param($key) =~ /^\s*$/);
# next if ($key !~ /^THUMB$/);
# $Number = $1;
#
# if ($query->param($key) =~ /([^\/\\]+)$/) {
# $Filename2 = $1;
# $Filename2 =~ s/^\.+//;
# $File_Handle2 = $query->param($key);
#
# }
#
#
# open(LOG, ">../../PDC/$CAT/$Filename2") || &ErrorMessage2;
#
# undef $BytesRead;
# undef $Buffer;
#
# while ($Bytes = read($File_Handle2,$Buffer,1024)) {
# $BytesRead += $Bytes;
# print LOG $Buffer;
# }
#
# push(@Files_Written2, "../../PDC/$CAT/$Filename2");
# $TOTAL_BYTES += $BytesRead;
# $Confirmation{$File_Handle2} = $BytesRead;
#
# close($File_Handle2);
# close(LOG);
#
# chmod (0777, "../../PDC/$CAT/$Filename2");
#
#
#########################################################
.............

The above has me confused. For three years I've had more of less nonstop daily
working code that does what you are asking about, but it looks very little like
yours.

I know that with CGI.pm you may use a filefield() in a mutilpart form (and you
may use several differently named filefilelds in a table with one submit button
for multiple file uploading) to upload a file or files that you then read via
those names with the upload() function of CGI, but I do not see those in your
code. Have you looked at the examples in the CGI.pm docs? Is your CGI a
multipart form?

BTW, 'use strict' may be incompatible with some file uploads via CGI due to the
passed handle syntax. I don't see stricture in your example though.
 
C

ctcgag

Melissa McGehee said:
Hi there! Been a while...3 years... but I'm back!

I have a script that uploads ONE user file. But I want to upload two.
This seems like a simple question...but in the newsgroup messages
downloaded, I cannot find anything that matches.

Please advise what I can do to upload multiple files. I have a section
commented out below that was SUPPOSED to allow the second file to
upload...but never worked. ALL SUGGESTIONS WELCOMED!

Many thanks! (and it's great to be back...)

I have a script that does that. I'll be glad to help you, but I'm not
going to wade through 140 lines of irrelevant code to do so. Please trim
your code to minimal necessary to show the problem. (Most likely, once
you do that the problem will be revealed, and you won't need our help
anymore.)

Thanks,

Xho
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top