Limit the types of extension that can be uploaded

R

Ron

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top