2

I want to calculate the size of a folder with all the sub-folders included. I know I have to do something with RecursiveDirectoryIterator, but it does not count the size of the folder including the sub-folders.

This is my root directory:

$MainDir = 'uploads/sfm/'.$UserID;

This is how I try to count the size of all files together, included the files in the sub-folders:

if (is_dir($MainDir)) { 
    $SumStorage = 0;
    foreach (new RecursiveDirectoryIterator($MainDir) as $file) {
        if ($file->isFile()) {
            $SumStorage += $file->getSize();
        }
    }

    $UsedStorage = $SumStorage/$LimitStorage*100;    
}

But it does not count the total size of all the files.

What is going wrong?

Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
Jack Maessen
  • 1,780
  • 4
  • 19
  • 51
  • 4
    already find the solution her: http://stackoverflow.com/questions/2788002/i-want-get-the-sum-of-files-size-in-folder-by-php – Jack Maessen May 03 '16 at 14:55
  • or some thing like: [php get directory size](http://stackoverflow.com/questions/478121/php-get-directory-size) – DIEGO CARRASCAL May 03 '16 at 15:10
  • Possible duplicate of [i want get the sum of files size in folder by php](https://stackoverflow.com/questions/2788002/i-want-get-the-sum-of-files-size-in-folder-by-php) – Daniel Sep 29 '18 at 11:41

0 Answers0