本文实例讲述了php计算整个目录大小的方法。分享给大家供大家参考。具体实现方法如下:
/**
* calculate the full size of a directory
*
* @author jonas john
* @version 0.2
* @param string $directorypath directory path
*/
function calcdirectorysize($directorypath) {
// i reccomend using a normalize_path function here
// to make sure $directorypath contains an ending slash
// to display a good looking size you can use a readable_filesize
// function.
$size = 0;
$dir = opendir($directorypath);
if (!$dir)
return -1;
while (($file = readdir($dir)) !== false) {
// skip file pointers
if ($file[0] == '.') continue;
// go recursive down, or add the file size
if (is_dir($directorypath . $file))
$size += calcdirectorysize($directorypath . $file . directory_separator);
else
$size += filesize($directorypath . $file);
}
closedir($dir);
return $size;
}
//使用范例:
$sizeinbytes = calcdirectorysize('data/');
希望本文所述对大家的php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!