Recursively chmod/chown/chgrp all files and folder within a directory
This should be helpful. EDITED: some syntax errors corrected
function fsmodify($obj) {
$chunks = explode('/', $obj);
chmod($obj, is_dir($obj) ? 0755 : 0644);
chown($obj, $chunks[2]);
chgrp($obj, $chunks[2]);
}
function fsmodifyr($dir)
{
if($objs = glob($dir."/*")) {
foreach($objs as $obj) {
fsmodify($obj);
if(is_dir($obj)) fsmodifyr($obj);
}
}
return fsmodify($dir);
}
You can perform a system call
system("/bin/chmod -R $mod $root");
system("/bin/chown -R $user $root");
system("/bin/chgrp -R $user $root");
of course you use escapeshellarg() or escapeshellcmd() in order to avoid executing arbitrary commands