public static function dirSize(string $directory, bool $includeDirAllocSize = false): int
    {
        $size = 0;
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
            /**
             * @var \SplFileInfo $file
             */
            if ($file->isFile()) {
                $size += filesize($file->getRealPath());
            } else {
                if ($includeDirAllocSize) {
                    $size += $file->getSize();
                }
            }
        }

        return $size;
    }
public static function dirSize(string $directory, bool $includeDirAllocSize = false): int
    {
        $size = 0;
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
            /**
             * @var \SplFileInfo $file
             */
            if ($file->isFile()) {
                $size += filesize($file->getRealPath());
            } else {
                if ($includeDirAllocSize) {
                    $size += $file->getSize();
                }
            }
        }

        return $size;
    }
public static function dirSize ( string $ directory , bool $ includeDirAllocSize = false ) : int { $ size = 0 ; foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ directory ) ) as $ file ) { /**
             * @var \SplFileInfo $file
             */ if ( $ file -> isFile ( ) ) { $ size += filesize ( $ file -> getRealPath ( ) ) ; } else { if ( $ includeDirAllocSize ) { $ size += $ file -> getSize ( ) ; } } } return $ size ; }
Get the directory size
@param string $directory
@param bool $includeDirAllocSize
@return integer
Get the directory size