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?
I think yours won't go recursive in case of folders, I fixed this case.
My solution will change all files and folder recursively to 0777. I use DirecotryIterator, it's much cleaner instead of opendir and while loop.
Here improved version of the recursive chmod that skips files with the same permissions.
This is tested and works like a charm: