note 34528 added to function.disk-free-space
| From: | nospam at jusunlee dot com | Date: | Wed, 30 Jul 2003 01:45:05 +0000 |
| Subject: | note 34528 added to function.disk-free-space | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52978@lists.php.net to get a copy of this message | ||
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';
?>
----
Manual Page -- http://www.php.net/manual/en/function.disk-free-space.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34528
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34528&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34528&report=yes