I want to recursively set the folder and file permissions. Folders should get 750 and files 644. I found this and made some adaptions. Would this one work?
<?php
function chmod_r($Path) {
$dp = opendir($Path);
while($File = readdir($dp)) {
if($File != "." AND $File != "..") {
if(is_dir($File)){
chmod($File, 0750);
}else{
chmod($Path."/".$File, 0644);
if(is_dir($Path."/".$File)) {
chmod_r($Path."/".$File);
}
}
}
}
closedir($dp);
}
?>
Why don't use find tool for this?
exec ("find /path/to/folder -type d -exec chmod 0750 {} +");
exec ("find /path/to/folder -type f -exec chmod 0644 {} +");