I don't know what to call this, but I'm confused! I have a form that uploads images (upload#). Since I have the option of uploading more than 1 file at a time, I pass the work to a subroutine with an increment on $num.

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>";

In reply to difficult error checking by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.