Christine 0 Newbie Poster

I can upload one file and would like to allow for 4 - 6 file uploads. I did not write the upload code and all I need is to add more uploads and I am not sure how to alter the code.

# maximum file size allowed (kilo bytes)
$max = 2000;

# if a file is successfully uploaded, enter a URL to redirect to.
# leave this blank to have the default message printed
$redirect = "";

# if you would like to be notified of uploads, enter your email address
# between the SINGLE quotes. leave this blank if you would not like to be notified
$notify = '';

# UNIX users, if you entered a value for $notify, you must also enter your
# server's sendmail path. It usually looks something like : /usr/sbin/sendmail
$send_mail_path = "/usr/sbin/sendmail";

# WINDOWS users, if you entered a value for $notify, you must also enter your
# server's SMTP path. It usually looks something like : mail.servername.com
$smtp_path = "mail.yourserver.com";

# set to 1 if you would like all files in the directory printed to the web page
# after a successful upload (only printed if redirect is off). Set to 0 if you
# do not want filenames printed to web page
$print_contents = 0;

# allow overwrites? 1 = yes, 0 = no (0 will rename file with a number on the end, the
# highest number is the latest file)
$overwrite = 0;

# file types allowed, enter each type on a new line
# Enter the word "ALL" in uppercase, to accept all file types.
@types = qw~

png
gif
jpg
jpeg
pdf
ppt
txt
doc
dox
html
htm

~;

$folder =~ s/(\/|\\)$//ig;

$OS = $^O; # operating system name
if($OS =~ /win/i) { $isWIN = 1; }
else {$isUNIX = 1;}

if($isWIN){ $S{S} = "\\"; }
else { $S{S} = "/";} # seperator used in paths

$ScriptURL = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}";


$query = new CGI; # create a new object
my @VAL = $query->param; #get all form field names

foreach(@VAL){
        $FORM{$_} = $query->param($_); # put all fields and values in hash
}

my @files;
foreach(keys %FORM){
        if($_ =~ /^upfile/){
                push(@files, $_); # place the field NAME in an array
        }
}

$imageError = 1;
foreach (@files){
        # upload each file, pass the form field NAME if it has a value
        if($query->param($_)){
                $returned = &psjs_upload($_, $fileSize, $fileType, $imageError);
        }
}

main script here then final script

sub psjs_upload {

        my ( $type_ok, $file_contents, $buffer, $destination ); # declare some vars

        my $file = $query->param($_[0]); # get the FILE name. $_[0] is the arg passed
        $_[3] = 1;

        ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
        $newName = "TEMP_$Year$DayOfYear$Hour$Minute$Second";

        $destination = $dir;

        my $limit = $max;
        $limit *= 1024; # convert limit from kilobytes to bytes

        # create another instance of the $file var. This will allow the script to play
        # with the new instance, without effecting the first instance. This was a major
        # flaw I found in the psupload script. The author was replacing spaces in the path
        # with underscores, so the script could not find a file to upload. He blammed the
        # error on browser problems.
        my $fileName    = $file;

        # get the extension
        my @file_type   = split(/\./, $fileName);
        # we can assume everything after the last . found is the extension
        my $file_type   = $file_type[$#file_type];
        $_[2] = "$file_type";#return file type

        # get the file name, this removes everything up to and including the
        # last slash found ( be it a forward or back slash )
        $fileName =~ s/^.*(\\|\/)//;

        # remove all spaces from new instance of filename var
        $fileName =~ s/\s+//ig;

        # check for any any non alpha numeric characters in filename (allow dots and dahses)
        $fileName =~ s/\./PsJsDoT/g;
        $fileName =~ s/\-/PsJsDaSh/g;
        if($fileName =~ /\W/){
                $fileName =~ s/\W/n/ig; # replace any bad chars with the letter "n"
        }
        $fileName =~ s/PsJsDoT/\./g;
        $fileName =~ s/PsJsDaSh/\-/g;

        # if $file_type matchs one of the types specified, make the $type_ok var true
        for($b = 0; $b < @types; $b++){
                if($file_type =~ /^$types[$b]$/i){
                        $type_ok++;
                }
                if($types[$b] eq "ALL"){
                        $type_ok++; # if ALL keyword is found, increment $type_ok var.
                }
        }

        # if ok, check if overwrite is allowed
        if($type_ok){
                # create a new file on the server using the formatted ( new instance ) filename
                if(open(NEW, ">$destination$S{S}$newName.$file_type")){ #new was file

                        if($isWIN){binmode NEW;} # if it's a WIN server, switch to binary mode
                        # start reading users HD 1 kb at a time.
                        while (read($file, $buffer, 1024)){
                                # print each kb to the new file on the server
                                print NEW $buffer;
                        }
                        # close the new file on the server and we're done
                        close NEW;
                } else {
                        # return the server's error message if the new file could not be created
                        return "Error: Could not open new file on server. $!~";
                }

                # check limit hasn't just been overshot
                if(-s "$destination$S{S}$newName.$file_type" > $limit){ # -s is the file size
                        unlink("$destination$S{S}$newName.$file_type"); # delete it if it's over the specified limit
                        return "~File exceeded limitations : $fileName~";
                }
        } else {
                return "~Bad file type : $file_type~";
        }

        # check if file has actually been uploaded, by checking the file has a size
        if(-s "$destination$S{S}$newName.$file_type"){
                $_[1] = (-s "$destination$S{S}$newName.$file_type"); #file size in bytes
                $_[3] = 0; #No error
                return "$newName.$file_type"; #success
        } else {
                # delete the file as it has no content
                unlink("$destination$S{S}$newName.$file_type");
                # user probably entered an incorrect path to file
                return "~Upload failed : No data in $fileName. No size on server's copy of file.\n Check the path entered.~";
        }
}

I tried just adding additional files - but it apparently needs addtional tweaking or am I missing something?

$file           = param('upfile');
$filea          = param('upfile');
$fileb          = param('upfile');
$filec          = param('upfile');