用print_r()函数打印相关的目录..得到你要的信息.

解决方案 »

  1.   

    不过print_r()好象要php4.3.0h后的版本才支持..
      

  2.   

    *nix下可以直接执行系统命令
    system('du -s /home');
    win下面好像没有直接的命令,可以用下面的函数。
    <?php
    function GetDirSize($dir){
    $tmp=`dir /S /-C $dir`;
    preg_match_all('/\d{4}\-\d{2}-\d{2}\s*\d{2}:\d{2}\s*(\d+)\s*(.*)/i', $tmp, $arr);
    return array_sum($arr[1]);
    }
    echo GetDirSize('d:\backup');
    ?>
      

  3.   

    用递归实现,速度稍慢,包括子目录
    <?php
    echo dirsize('c:/winnt');function dirsize($path)
    {
    $path = preg_replace('/[\/\\\]$|$/','/',$path);

    $handle = dir($path);
    while (($file = $handle->read()) !== false)
    {
    if (is_file($path.$file))
    {
    $filesize += filesize($path.$file);
    }
    elseif (($file != '.' && $file != '..'))
    {
    $filesize += dirsize($path.$file);
    }
    }
    $handle->close();
    return $filesize;
    }
    ?>
      

  4.   

    再加个是否包括子目录,默认包括。function dirsize($path,$S=true)
    {
    $path = preg_replace('/[\/\\\]$|$/','/',$path);

    $handle = dir($path);
    while (($file = $handle->read()) !== false)
    {
    if (is_file($path.$file))
    {
    $filesize += filesize($path.$file);
    }
    elseif ($S && ($file != '.' && $file != '..'))
    {
    $filesize += dirsize($path.$file);
    }
    }
    $handle->close();
    return $filesize;
    }