___DATA___ dog.gif cat.gif bird.gif Upload form attempts: upload1 = bat.gif upload2 = dog.gif upload3 = gopher.gif Print out results: bat.gif was successfull dog.gif was a duplicate, not uploaded gopher.gif was successfull #### if ( param('upload1') ) { my $num = 1; &dirty_work($num); } if ( param('upload2') ) { my $num = 2; &dirty_work($num); } if ( param('upload3') ) { my $num = 3; &dirty_work($num); } if ( param('upload4') ) { my $num = 4; &dirty_work($num); } sub dirty_work { my $num = shift; # take form data my $remotefile = param("upload$num"); # make new variable to prevent overwriting of form data my $filename = $remotefile; my $title = param("title$num"); $title =~ s/&/&\#38/g; my $comments = param("comments$num"); $comments =~ s/&/&\#38/g; # remove all directories in the file name path $filename =~ s/^.*[\\\/]//; my $localfile = "$uploaddir/$filename"; my $type = uploadInfo($remotefile)->{'Content-Type'}; unless ( $type eq 'image/pjpeg' || $type eq 'image/gif' || $type eq 'image/bmp') { print "Wrong! This is not a supported file type."; exit; } ################################## # Check for duplicate filenames ################################## foreach (keys %upload) { my ($filename_check, $title_check, $comments_check, $w_check, $h_check, $count_check) = split(/::/, $upload{$_}); if($filename eq "$filename_check") { print "
Duplicate filename found: $filename_check
"; exit; } } print "
Uploaded $filename
";