Limit the types of extension that can be uploaded

Discussion in 'Perl Misc' started by Ron, Jul 21, 2003.

  1. Ron

    Ron Guest

    Trying to limit the type (file extension) of files that can be uploaded.
    Using cgi. Can anyone tell my what is wrong with this script? I get a
    server 500 Error.

    Thanks,
    Ron

    #Limit the types of extension that can be uploaded
    @bad_extensions = ();
    @good_extensions = ('dss');
    #undef @bad_extensions if @good_extensions;

    for(my $a = 1; $a <= $max_num_files; $a++) {
    my $req = new CGI;
    if($req->param("FILE$a")) {
    my $file = $req->param("FILE$a");
    my $filename = $file;
    $filename =~ s/^.*(\\|\/)//;
    $filename =~ s/ +/\_/g;
    #For IE
    $filename =~ s/ +/\_/g;
    #For Opera
    $filename =~ s/\"//g;
    my $proceed_type = 0;
    if(@good_extensions) {
    foreach(@good_extensions) {
    my $ext = $_;
    $ext =~ s/\.//g;
    if($filename =~ /\.$ext$/) {
    $proceed_type = 1;
    last;
    }
    }
    unless($proceed_type) {
    push(@was_not_good_type, $filename);
    }
    }
    elsif(@bad_extensions) {
    $proceed_type = 1;
    foreach(@bad_extensions) {
    my $ext = $_;
    $ext =~ s/\.//g;
    if($filename =~ /\.$ext$/) {
    $proceed_type = 0;
    last;
    }
    }
    unless($proceed_type) {
    push(@was_a_bad_type, $filename);
    }

    if(@was_not_good_type) {print "<B>The following file(s) were not stored as
    their file extension<BR>did not match any of the valid extensions specified
    in the program:<BR><BR>\n"; print join("<BR>", @was_not_good_type); print
    "<BR><BR>\n"}
    if(@was_a_bad_type) {print "<B>The following files were not stored as their
    file extension<BR>are on the list of extensions not permitted for
    upload:<BR><BR>\n"; print join("<BR>", @was_a_bad_type); print "<BR><BR>\n"}
     
    Ron, Jul 21, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt G
    Replies:
    1
    Views:
    1,180
    Deepak Kumar Vasudevan
    Aug 22, 2003
  2. Soren Kuula
    Replies:
    2
    Views:
    577
    Henry S. Thompson
    Dec 1, 2005
  3. javadev
    Replies:
    8
    Views:
    400
    Simon Brooke
    Nov 8, 2006
  4. sandSpiderX
    Replies:
    20
    Views:
    707
    Lionel B
    Jun 27, 2005
  5. Replies:
    1
    Views:
    1,098
    Victor Bazarov
    Jun 28, 2005
Loading...

Share This Page