App\services\Storage::getDirSize PHP Method

getDirSize() public static method

Recursively count the size of specified directory
public static getDirSize ( string $dir ) : int,
$dir string
return int,
    public static function getDirSize($dir)
    {
        $resource = opendir($dir);
        $size = 0;
        while ($filename = @readdir($resource)) {
            if ($filename != "." && $filename != "..") {
                $path = "{$dir}/{$filename}";
                if (is_dir($path)) {
                    // recursion
                    $size += self::getDirSize($path);
                } else {
                    if (is_file($path)) {
                        $size += filesize($path);
                    }
                }
            }
        }
        closedir($resource);
        return $size;
    }