I am working on a site which builds other sites. Some if it I use copy() to create the files and directories, other times I\'m building XML files in php and using DOMDocume
system("/bin/chmod -R $mod $root");
system("/usr/bin/find -type d $root -print0 | xargs -0 | /bin/chmod $moddir");
system("/bin/chown -R $user $root");
system("/bin/chgrp -R $user $root");
Invalid mode 493 means you passed your mode as decimal. Convert to octal string first.
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