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

前端 未结 3 1618
别那么骄傲
别那么骄傲 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: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);
        }   
    

提交回复
热议问题