PHP实现统计目录文件大小

/**
 * 统计目录文件大小的函数
 * @param $dir 文件路径
 * @author [email protected]
 */
function dirsize($dir)
{
    @$dh = opendir($dir);
    $size = 0;
    while($file = @readdir($dh))
    {
        if($file != "." and $file != "..")
        {
            $path = $dir . "/" . $file;

            if(is_dir($path))
            {
                $size += dirsize($path);
            } elseif(is_file($path)) {
                $size += filesize($path);
            }
        }
    }

    @closedir($dh);
    return $size;
 }

猜你喜欢

转载自www.cnblogs.com/zhangxilong/p/12767323.html
今日推荐