note 34528 deleted from function.disk-free-space by aidan
| From: | aidan@php.net | Date: | Sat, 16 Oct 2004 00:40:55 +0000 |
| Subject: | note 34528 deleted from function.disk-free-space by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78628@lists.php.net to get a copy of this message | ||
Note Submitter: nospam at jusunlee dot com
----
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';
?>