chmod recursive

function chmod_r($path, $filemode) {
 
	if (!is_dir($path)) {
 
  		return chmod($path, $filemode);
 	}
 
 	$dh = opendir($path);
 
 	while ($file = readdir($dh)) {
 
	  if ($file != '.' && $file != '..') {
 
		$fullpath = $path.'/'.$file;
 
	   	if (!is_dir($fullpath)) {
 
	    		if (!chmod($fullpath, $filemode)) {
 
	     			return false;
	    		}
 
	   		} else {
 
	    		if (!chmod_r($fullpath, $filemode)) {
 
	     			return false;
	    		}
	   	}
	  }
	}
 
 	closedir($dh);
 
 	if (chmod($path, $filemode)) {
 
  		return true;
 	}
 
 	return false;
}

usage:

chmod_r('your/path', 0777);
  1. Hi, just use chmod -R for recursive

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>