note 15203 added to function.disk-total-space
| From: | flagzen at libero dot it | Date: | Fri, 31 Aug 2001 15:35:13 +0000 |
| Subject: | note 15203 added to function.disk-total-space | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17432@lists.php.net to get a copy of this message | ||
This is an enhanced version of the dirsize function written above, with recursion so that making
dirsize($dir) returns the total size of the dir, including all subdirectories.
I hope that this function will be useful to someone.
function dirsize($dir) {
// calculate the size of files in $dir, (it descends recursively into other dirs)
$dh = opendir($dir);
$size = 0;
while (($file = readdir($dh)) !== false)
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;
}
http://www.php.net/manual/it/function.disk-total-space.php