note 36495 added to function.chown
| From: | Richard at rn2 dot php dot net | Date: | Sun, 12 Oct 2003 00:49:49 +0000 |
| Subject: | note 36495 added to function.chown | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58314@lists.php.net to get a copy of this message | ||
As far as I can tell, PHP's built in functions will not do a recursive chown or chgrp. But it
wouldn't be hard to write a function for this. Here is some starter code based on an example
written by John Coggeshall which I found at http://www.coggeshall.org :
function recurse_chown_chgrp($path2dir, $uid, $gid){
$dir = new dir($path2dir);
while(($file = $dir->read()) !== false) {
if(is_dir($dir->path.$file)) {
recurse_chown_chgrp($dir->path.$file, $uid, $gid);
} else {
chown($file, $uid);
chgrp($file, $gid);
}
}
$dir->close();
}
I have not tested this code (but I think it will work) because for my current needs, a simple
exec("chown -r $user.$group $path"); is sufficient. I would need this code if I were not
in control of the contents of these variables because they can be dangerous on the command line.
----
Manual Page -- http://www.php.net/manual/en/function.chown.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36495
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36495&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36495&report=yes
Search -- http://master.php.net/manage/user-notes.php