php 递归求得目录大小

    /*
    *    递归求得目录大小
    *    @param  $dir  目录
    */
    function dirsize($dir){
        $allsize = 0;
        $handle = opendir($dir);
        while($file = readdir($handle)){
            if($file != '.' && $file != '..'){
                $file = $dir . '/' . $file;
                if(is_dir($file)){
                    $allsize += dirsize($file);
                }else{
                    $allsize += filesize($file);
                }
            }
            
        }
        return $allsize;
    }
原文地址:https://www.cnblogs.com/hejun695/p/5336453.html