Hello, I was wondering if somebody would be able to help me debug this file upload script: What I'd like the script to do: Allow users to upload pictures to my (their)websites. Restrict to jpg,jpeg,gif only.Preserve their filename. At the moment it uploads the file and uses counter number as unique name and jpg as default extension, even so it might be a gif file!. I am not a programmer, and fiddled with this script for the last 3 days. Any help really appreciated!
#!/usr/local/bin/perl use CGI; use CGI::Carp qw/fatalsToBrowser/; print "Content-type:text/html\n\n"; $cgi = new CGI; $dir = "/usr/home/mywebsite/public_html/welcome/graphicsincoming"; $file = $cgi->param('file'); if ($file =~ /.jpeg/gi){ &start; } elsif ($file =~ /.gif/gi){ &start; } elsif ($file =~ /.jpg/gi){ &start; } else{ dienice("Sorry, but you have either not selected a file to upload +or you are trying to upload an invalid picture file. Only the follow +ing file extensions are supported: /.jpeg/.gif/.jpg. Please press th +e 'back' button below to return to the Upload form."); } sub start{ open(COUNT,"</usr/home/mywebsite/public_html/cgi-bin/counter/count.dat +"); @numbers = <COUNT>; chomp(@numbers); close(COUNT); $filename = @numbers[-1]; $filename++; $file_name = "$filename"; $file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filenam +e open(LOCAL, ">$dir/$file_name") or die $!; while(<$file>) { print LOCAL $_; }

In reply to upload.cgi my script is bugged 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.