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?
This is tested and works like a charm:
header('Content-Type: text/plain');
/**
* Changes permissions on files and directories within $dir and dives recursively
* into found subdirectories.
*/
function chmod_r($dir, $dirPermissions, $filePermissions) {
$dp = opendir($dir);
while($file = readdir($dp)) {
if (($file == ".") || ($file == ".."))
continue;
$fullPath = $dir."/".$file;
if(is_dir($fullPath)) {
echo('DIR:' . $fullPath . "\n");
chmod($fullPath, $dirPermissions);
chmod_r($fullPath, $dirPermissions, $filePermissions);
} else {
echo('FILE:' . $fullPath . "\n");
chmod($fullPath, $filePermissions);
}
}
closedir($dp);
}
chmod_r(dirname(__FILE__), 0755, 0755);
?>