递归chmod / chown / chgrp目录中的所有文件和文件夹 [英] Recursively chmod/chown/chgrp all files and folder within a directory
问题描述
我正在建立其他网站的网站。有些如果我使用 copy()创建文件和目录,其他时候我正在构建XML文件,并使用 DOMDocument :: save 保存它们。最终结果是一个根文件夹,各种各样的乱七八糟的权限。我一直在改变文件和文件夹,我去,这在某种程度上的话,但我特别有麻烦,当涉及到使用 copy()
。
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 DOMDocument::save to save them. The end result is a root folder with all sorts of messed up permissions. I've beening modding files and folders as I go, which words to some extent, but I'm particularly having trouble when it comes to using copy()
.
(这是我到目前为止的地方 http://pastebin.com/SBE8vtFX,attn: function modPath($ path)
)
(This is where I'm at so far http://pastebin.com/SBE8vtFX, attn: function modPath($path)
)
我想采用不同的方法递归 chmod / chown / chgrp ,我的文档根目录中的所有文件和文件夹会立即以我的规格 。
I want to take a different approach and recursively chmod/chown/chgrp all the files and folders within my document root to my specifications at once.
文档根
/home/mysite/public_html
和之内public_html
我有
-rwxrwxrwx 1 mysite mysite 348 Aug 31 10:49 index.php
d--------x 5 root root 4096 Aug 30 10:21 folder1
drwxrwxrwx 2 mysite mysite 4096 Aug 30 09:41 folder2
如何立即修改指定目录中的所有文件?我想区分目录和文件夹之间不同的chmod设置。这需要是一个PHP解决方案。
My question:
How can I mod all files within a specified directory at once? I want to differentiate different chmod settings between directories and folders as well. This needs to be a PHP solution.
这是我可以得到
<?php
function modAll($root) {
$aPath = explode("/", $root);
$user = $aPath[2];
/* Some sort of looping through $root */ {
$mod = (is_dir($thisfileorfolder) ? 0755 : 0644);
chmod($thisfileorfolder, $mod);
chown($thisfileorfolder, $user);
chgrp($thisfileorfolder, $user);
}
}
?>
推荐答案
EDITED:纠正了一些语法错误
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);
}
这篇关于递归chmod / chown / chgrp目录中的所有文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!