Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursively chmod/chown/chgrp all files and folder within a directory
    text
    copied!<p>I am working on a site which builds other sites. Some if it I use <a href="http://php.net/manual/en/function.copy.php" rel="noreferrer">copy()</a> to create the files and directories, other times I'm building XML files in php and using <a href="http://php.net/manual/en/domdocument.save.php" rel="noreferrer">DOMDocument::save</a> 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 <code>copy()</code>.</p> <p>(This is where I'm at so far <a href="http://pastebin.com/SBE8vtFX" rel="noreferrer">http://pastebin.com/SBE8vtFX</a>, attn: <code>function modPath($path)</code>)</p> <p>I want to take a different approach and recursively <strong>chmod/chown/chgrp</strong> all the files and folders within my document root to my specifications <em>at once</em>.</p> <p>Take for example the document root</p> <pre><code>/home/mysite/public_html </code></pre> <p>and within <code>public_html</code> I have</p> <pre><code>-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 </code></pre> <hr> <h2>My question:</h2> <p>How can I mod <strong>all</strong> 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.</p> <p>This is as far as I can get</p> <pre><code>&lt;?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); } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload