Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Limit the types of extension that can be uploaded

Reply
Thread Tools

Limit the types of extension that can be uploaded

 
 
Ron
Guest
Posts: n/a
 
      07-21-2003
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"}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Some shareware has a time limit and the software will not work after the time limit has expired. anthony crowder Computer Support 20 01-16-2007 10:01 AM
Limit uploaded image file dimensions javadev Java 8 11-08-2006 06:16 PM
c program, file size limit, how to solve? 2G bytes limit. guru.slt@gmail.com C++ 1 06-27-2005 11:05 PM
Virus-Scanning uploaded files uploaded? Matt G ASP .Net 1 08-22-2003 05:44 AM



Advertisments