nospam at jusunlee dot com
30-Jul-2003 11:45
The above is only useful if you need to find the total used space of a
mountpoint. If you are looking for a script that determines the total used
space of a directory and all of its contents (including subdirectories),
heres a recursive function that should do the work.
<?
$total
= 0;
function spaceUsed($dir) {
if (is_dir($dir)) {
if ($dh =
opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if
(is_dir($dir.$file) && $file != '.' && $file != '..') {
spaceUsed($dir.$file.'/');
} else {
$GLOBALS['total'] +=
filesize($dir.$file);
}
}
closedir($dh);
}
}
}
spaceUsed('/path/to/directory/');
$total /=
1048576;
echo round($total, 1).' mb';
?>