PHP - CHMOD a directory recursively

The script below loops over the specified directory and chmods its files, directories and subdirectories recursively.

  function chmodDirectory( $path = ‘.’, $level = 0 ){  
$ignore = array( ‘cgi-bin’, ‘.’, ‘..’ );
$dh = ( $path );
while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory
if( !in_array( $file, $ignore ) ){
if( is_dir( “$path/$file” ) ){
chmod(”$path/$file”,0777);
chmodDirectory( “$path/$file”, ($level+1));
} else {
chmod(”$path/$file”,0777); // desired permission settings
}//elseif
}//if in array
}//while
closedir( $dh );
}//function
chmodDirectory(”the_directory/”,0);
?>
Comments
Add New
Powered by !JoomlaComment 3.26

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Help my beer fund

RocketTheme Joomla Templates