How do you change mode of files from cgi application?
like data/
data/ddd
if data is 0777, can you change all subdirectories and files inside data to 0777 also by CGI application? or it has to be done every signle one from the cmd line?
Perl comes with a [tt]chmod[/tt] subroutine. See the [tt]perlfunc[/tt] pages for a full explanation. You can pass an array of files to this subroutine, for example:
Code:
my @files = qw( data/ddd data/eee );
$mode = 0777; # octal number
$changed = chmod( $mode, @files );
You could also use [tt]chmod[/tt] along with the [tt]File::Find[/tt] package to recurse through your directory. Something like:
Code:
use File::Find;
sub change {
my $mode = 0777;
chmod $mode, $_ if -f; # change if regular file
}
# list of directories
my @dirs = qw( a b );
# recursively modify permissions on regular files
find( \&change, @dirs );
Yes, I understand that we can use chmod to change file permissions, but I also look for a way to chmod for DIRECTORY so that I can write files to.
It is very difficult to go to 100's directory and chmod them just to be able to write to them.
The problem arise because I used a image gallery program, and this program need the all photo directories to be chmod'ed to 0777 so that they can write information and upload files to. And I have 1000's, I mean 1000's, categories. It will take me the whole day just to do that.
So I would like to write small function that automatically chmod every DIRECTORY for me to 0777, so that I can use the program.
Really appreciate if you can point me to any direction.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.