Skip to content

Instantly share code, notes, and snippets.

@genakim
Forked from eusonlito/foldersize.php
Created June 28, 2021 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genakim/1410bf40b1e4d540887201220f0fecaf to your computer and use it in GitHub Desktop.
Save genakim/1410bf40b1e4d540887201220f0fecaf to your computer and use it in GitHub Desktop.
PHP function to get the folder size including subfolders
<?php
function folderSize ($dir)
{
$size = 0;
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
$size += is_file($each) ? filesize($each) : folderSize($each);
}
return $size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment