function getDirectorySize($path) { $rv = array('size' => 0, 'count' => 0, 'dircount' => 0); $base = $path; $stack = array($path); while (($dir = opendir(array_pop($stack))) !== false) { while (($file = readdir($dir)) !== false) { if ($file != '.' && $file != '..') { $nextpath = "$base/$file"; ++$rv['count']; if (is_dir($nextpath)) { ++$rv['dircount']; array_push($stack, $nextpath); } else { $rv['size'] += filesize($nextpath); } } } } return $rv; }