Hi, I am wondering if there is a mod to allow only certain file extension types to be uploaded using fileman?
Hi Malteser:
So if you only want to allow certain file extensions or diallow (if you
want to disallow by default) then change the following subroutine:
1 sub is_valid_file {
2 # -----------------------------------------------------
3 # Checks to see if a file is valid (proper form).
4 #
5 my ($file, $okfile) = "";
6 $file = shift;
7
8 ($file =~ m,^([A-Za-z0-9\-_.]*)$,) ?
9 ($okfile = $1) :
10 (return ($file, "Illegal Characters in Filename. Please use
letters, numbers, -, _ and . only."));
11 ($file =~ m,\.\.,) and return ($file, "No double .. allowed in
file names.");
12 ($file =~ m,^\.,) and return ($file, "no leading '.' in file
names.");
13 (length($file) > 20) and return ($file, "File name is too long.
Please keep it to under 20 characters.");
14 return ($okfile, "");
15}
assuming you do not want txt file to be uploaded then
insert this line at line 11:
($file =~ m,\.txt$,i) and return ($file, "No txt file allowed");
and so on for each file extension.
However, if you don't want to allow any file extensions by default and
only allow certain files then insert at line 11: in this case only allow
txt file and disallow any other files by default
($file =~ m,\.txt$,i) or return ($file, "No txt file allowed");
you can cascade this like this:
($file =~ m,\.txt$,i) or ($file =~ m,\.jpg$,i) or return ($file,
"File not allowed");
The other thing about limiting the filesize to be uploaded:
%config = (
root_dir => "c:/WebSite/htdocs",
logfile => "c:/WebSite/htdocs/fileman/fileman.log",
password_dir => "/gossamer/www/scripts/fileman/pass",
root_url => "http://localhost",
script_url => "http://localhost/fileman/fileman.cgi",
icondir_url => 'http://localhost/fileman/icons',
use_flock => 1,
allowed_space => 10000000000,
max_upload => 75,
show_size => 1,
show_date => 1,
show_perm => 1,
show_icon => 1,
show_pass => 1,
version => '1.0'
);
change max_upload to the appropriate size.
Hope that helps
Cheers
Sun
So if you only want to allow certain file extensions or diallow (if you
want to disallow by default) then change the following subroutine:
1 sub is_valid_file {
2 # -----------------------------------------------------
3 # Checks to see if a file is valid (proper form).
4 #
5 my ($file, $okfile) = "";
6 $file = shift;
7
8 ($file =~ m,^([A-Za-z0-9\-_.]*)$,) ?
9 ($okfile = $1) :
10 (return ($file, "Illegal Characters in Filename. Please use
letters, numbers, -, _ and . only."));
11 ($file =~ m,\.\.,) and return ($file, "No double .. allowed in
file names.");
12 ($file =~ m,^\.,) and return ($file, "no leading '.' in file
names.");
13 (length($file) > 20) and return ($file, "File name is too long.
Please keep it to under 20 characters.");
14 return ($okfile, "");
15}
assuming you do not want txt file to be uploaded then
insert this line at line 11:
($file =~ m,\.txt$,i) and return ($file, "No txt file allowed");
and so on for each file extension.
However, if you don't want to allow any file extensions by default and
only allow certain files then insert at line 11: in this case only allow
txt file and disallow any other files by default
($file =~ m,\.txt$,i) or return ($file, "No txt file allowed");
you can cascade this like this:
($file =~ m,\.txt$,i) or ($file =~ m,\.jpg$,i) or return ($file,
"File not allowed");
The other thing about limiting the filesize to be uploaded:
%config = (
root_dir => "c:/WebSite/htdocs",
logfile => "c:/WebSite/htdocs/fileman/fileman.log",
password_dir => "/gossamer/www/scripts/fileman/pass",
root_url => "http://localhost",
script_url => "http://localhost/fileman/fileman.cgi",
icondir_url => 'http://localhost/fileman/icons',
use_flock => 1,
allowed_space => 10000000000,
max_upload => 75,
show_size => 1,
show_date => 1,
show_perm => 1,
show_icon => 1,
show_pass => 1,
version => '1.0'
);
change max_upload to the appropriate size.
Hope that helps
Cheers
Sun
Nov 22, 1999, 5:03 PM
Novice (12 posts)
Nov 22, 1999, 5:03 PM
Post #3 of 4
Views: 2210
Hi Sun, thanks so much for the help. However, there is still a slight problem:
There's no problem with inserting the following as an exclusion criterion for file extension:
($file =~ m,\.txt$,i) and return ($file, "No txt file allowed");
However, I get an error message whenever loading fileman.cgi (ie. on first run I alread get the error message before I can even access the file directory) if I use the "or" argument for the same line as an inclusion criterion for file extensions (which is what I want to do):
($file =~ m,\.txt$,i) or return ($file, "No txt file allowed");
sincerely,
Malteser
There's no problem with inserting the following as an exclusion criterion for file extension:
($file =~ m,\.txt$,i) and return ($file, "No txt file allowed");
However, I get an error message whenever loading fileman.cgi (ie. on first run I alread get the error message before I can even access the file directory) if I use the "or" argument for the same line as an inclusion criterion for file extensions (which is what I want to do):
($file =~ m,\.txt$,i) or return ($file, "No txt file allowed");
sincerely,
Malteser