note 36495 modified in function.chown by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:54:36 +0000 |
| Subject: | note 36495 modified in function.chown by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80044@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 :
<?php
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.
--was--
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.
http://php.net/manual/en/function.chown.php