I have done this before I just started with my root directory and and Started a variable called $count then i looped through the dir and look for files, I then got the filesize using
$basedir = "/www/somedir/";
chdir($basedir);
$dir = dir(".");
while ($file = $dir->read()) {
if (is_file($file)) {
$count = ($count + filesize($file));
}
if (is_dir($file)) {
$dirlist[] = $file;
}
This will get the filesize and add it up for the files in the main dir and place the directories into an array. Now I would loop through t the array and chdir into each one and get the counts if there are subdirs I would add them into the subdirs array like above
if (count($dirlist) > 0) {
while (list ($key, $val) = each ($dirlist)) {
chdir($val);
$dir = dir(".");
while ($file = $dir->read()) {
if (is_file($file)) {
$count = ($count + filesize($file));
}
if (is_dir($file)) {
$subdirlist[] = $file;
}
chdir($basedir);
}
}
This should work for the main dir and any sub dirs under it.