PHP - CHMOD a directory recursively

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

<?php
function chmodDirectory( $path = ‘.’, $level = 0 ){

$ignore = array( ‘cgi-bin’, ‘.’, ‘..’ );

$dh = @opendir( $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
+/-
Write comment
Name:
Email:
 
Website:
Title:
 
Please input the anti-spam code that you can read in the image.

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