Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Last active June 2, 2024 22:58
Show Gist options
  • Save eusonlito/5099936 to your computer and use it in GitHub Desktop.
Save eusonlito/5099936 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;
}
@webdev23
Copy link

webdev23 commented Jun 2, 2024

In GigaBytes:

return $size / 1e-9; //GigaBytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment