set permissions for all files and folders recursively

前端 未结 5 1240
执笔经年
执笔经年 2021-01-31 04:59

I want to recursively set the folder and file permissions. Folders should get 750 and files 644. I found this and made some adaptions. Would this one work?



        
5条回答
  •  自闭症患者
    2021-01-31 05:32

    My solution will change all files and folder recursively to 0777. I use DirecotryIterator, it's much cleaner instead of opendir and while loop.

    function chmod_r($path) {
        $dir = new DirectoryIterator($path);
        foreach ($dir as $item) {
            chmod($item->getPathname(), 0777);
            if ($item->isDir() && !$item->isDot()) {
                chmod_r($item->getPathname());
            }
        }
    }
    

提交回复
热议问题