Recursively chmod/chown/chgrp all files and folder within a directory

前端 未结 3 1613
别那么骄傲
别那么骄傲 2020-12-19 06:17

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

相关标签:
3条回答
  • 2020-12-19 07:02
    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.

    0 讨论(0)
  • 2020-12-19 07:11

    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);
        }   
    
    0 讨论(0)
  • 2020-12-19 07:14

    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

    0 讨论(0)
提交回复
热议问题