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?