Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Everything works fine except the new error checking I tried to make. Since each image filename is stored into a hash, I need them to be different. I tried using a foreach(keys.. to check, and this DOES work...kind of.
The problem is, if upload1 and upload2 are unique, but upload3 isn't, images 1 and 2 will be sucessful and image 3 will die. Likewise, if image 1 is a duplicate and 2 and 3 are different, because image1 dies, the rest can't be successfull.
Can someone help me figure out a way to set it up to print "$filename was uploaded" for ALL images that are unique, even if the image before it was a duplicate?
An example:
___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
SCRIPT:
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 e +q '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_che +ck, $count_check) = split(/::/, $upload{$_}); if($filename eq "$filename_check") { print "<center><font color=red>Duplicate filename found: $filename +_check</font></center>"; exit; } } print "<font color=blue><center>Uploaded $filename</font></center>";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: difficult error checking
by Sol-Invictus (Scribe) on Jan 28, 2004 at 21:48 UTC | |
|
Re: difficult error checking
by fireartist (Chaplain) on Jan 29, 2004 at 09:47 UTC |