function folderSize($dir) { $size = 0; foreach (glob(rtrim($dir, '/') . '/*', GLOB_NOSORT) as $each) { $size += is_file($each) ? filesize($each) : folderSize($each); } return $size; }
function folderSize($path, $blockSize) { $size = 0; $o = scandir($path); foreach ($o as $i => $f) { if ($f !== '.' && $f !== '..') { if (is_dir($path . '/' . $f)) { $size += folderSize($path . '/' . $f, $blockSize); } else { $s = filesize($path . '/' . $f); if ($blockSize) { $s = $s + $blockSize * (1 - ($s / $blockSize - floor($s / $blockSize))); $size += $s; } else { $size += $s; } } } } return $size; }