note 36529 added to function.disk-free-space
| From: | laurie at nospam dot oneuponedown dot com | Date: | Mon, 13 Oct 2003 20:05:13 +0000 |
| Subject: | note 36529 added to function.disk-free-space | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58555@lists.php.net to get a copy of this message | ||
Adapt/refinement to "nospam at jusunlee dot com" spaceUsed:
<?
// RETURNS THE TOTAL SIZE OF ALL FILES
// WITHIN A DIRECTORY AND SUBSEQUENT CHILD DIRECTORIES
// LIMITED TO DIRECTORIES AND FILES OWNED BY
// THE OPERATING USER (PHP/APACHE IN MOST CASES)
//
// RETURNS AN INT
//
function dir_size($DIR = FALSE) {
// IF DIR IS TRUE AND IS A DIRECTORY
if ($DIR &&
is_dir($DIR)) {
// ADD TRAILING SLASH
if (substr($DIR,-1) != "/") $DIR .= "/";
// OPEN DIRECTORY
if ($DIR_ID = opendir($DIR)) {
// LOOP THROUGH CONTENTS OF DIR
while (($ITEM = readdir($DIR_ID)) !== FALSE) {
// IF ITEM DOES NOT EQUAL "." AND ".."
if ($ITEM != "." &&
$ITEM != "..") {
// IF ITEM IS A DIRECTORY
if (is_dir($DIR . $ITEM)) {
// CALL FUNCTION RECURSIVELY
$SIZE += dir_size($DIR . $ITEM);
// ELSE ITEM IS A FILE
} else {
// ADD SIZE OF FILE
$SIZE += filesize($DIR . $ITEM);
}
}
}
// CLOSE DIRECTORY
closedir($DIR_ID);
}
}
// RETURN SIZE
return $SIZE;
}
print(dir_size("/path/to/directory/"));
?>
----
Manual Page -- http://www.php.net/manual/en/function.disk-free-space.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36529
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36529&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36529&report=yes
Search -- http://master.php.net/manage/user-notes.php