note 52360 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 13 Jul 2005 03:17:21 +0000 |
| Subject: | note 52360 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-91856@lists.php.net to get a copy of this message | ||
Note Submitter: development at lab-9 dot com
----
here a small function to retrieve a folder's size recursive :-) I don't know if there is
no function that retrieves a folder size or if I was just to dumb to find it :-)
hint: call the function with $output=true if you want to have also a status message where the
function read that stuff .. usually you don't need that
<?php
function get_folder_size($target, $output=false)
{
$sourcedir = opendir($target);
while(false !== ($filename = readdir($sourcedir)))
{
if($output)
{ echo "Processing: ".$target."/".$filename."<br>"; }
if($filename != "." && $filename != "..")
{
if(is_dir($target."/".$filename))
{
// recurse subdirectory; call of function recursive
$totalsize += get_folder_size($target."/".$filename, $exceptions);
}
else if(is_file($target."/".$filename))
{
$totalsize += filesize($target."/".$filename);
}
}
}
closedir($sourcedir);
return $totalsize;
}
$size = get_folder_size("/var/www/html", false);
// $size has the value of bytes found in directory
// output size in kb
echo "~".(int)($size/1024)."kb";
?>
greetingz, D.