public static function dirsize($dir, $createifmissing = false) {
		$dirsize = 0;
		if (!file_exists($dir)) {
			if ($createifmissing === true) {
				mkdir($dir);
				return 0;
			}
			throw new \Exception('Directory does not exist!', 400);
		}

		$dir_info = scandir($dir);

		if ($dir{(mb_strlen($dir) - 1)} !== '/') {
			$dir .= '/';
		}

		clearstatcache();
		foreach ($dir_info as $i => $member) {
			if ($member === '.' || $member === '..') {
				continue;
			}
			$abs_member = $dir.$member;
			if (is_file($abs_member)) {
				$dirsize += filesize($abs_member);
			} elseif (is_dir($abs_member)) {
				$dirsize += static::dirsize($abs_member.'/');
			}
		}
		return $dirsize;
	}
public static function dirsize($dir, $createifmissing = false) {
		$dirsize = 0;
		if (!file_exists($dir)) {
			if ($createifmissing === true) {
				mkdir($dir);
				return 0;
			}
			throw new \Exception('Directory does not exist!', 400);
		}

		$dir_info = scandir($dir);

		if ($dir{(mb_strlen($dir) - 1)} !== '/') {
			$dir .= '/';
		}

		clearstatcache();
		foreach ($dir_info as $i => $member) {
			if ($member === '.' || $member === '..') {
				continue;
			}
			$abs_member = $dir.$member;
			if (is_file($abs_member)) {
				$dirsize += filesize($abs_member);
			} elseif (is_dir($abs_member)) {
				$dirsize += static::dirsize($abs_member.'/');
			}
		}
		return $dirsize;
	}
public static function dirsize ( $ dir , $ createifmissing = false ) { $ dirsize = 0 ; if ( ! file_exists ( $ dir ) ) { if ( $ createifmissing === true ) { mkdir ( $ dir ) ; return 0 ; } throw new \ Exception ( 'Directory does not exist!' , 400 ) ; } $ dir_info = scandir ( $ dir ) ; if ( $ dir { ( mb_strlen ( $ dir ) - 1 ) } !== '/' ) { $ dir .= '/' ; } clearstatcache ( ) ; foreach ( $ dir_info as $ i => $ member ) { if ( $ member === '.' || $ member === '..' ) { continue ; } $ abs_member = $ dir . $ member ; if ( is_file ( $ abs_member ) ) { $ dirsize += filesize ( $ abs_member ) ; } elseif ( is_dir ( $ abs_member ) ) { $ dirsize += static :: dirsize ( $ abs_member . '/' ) ; } } return $ dirsize ; }
Get the disk usage of a given directory.

@param string $dir The absolute path to the directory to get the disk usage of.
@return int The disk usage of the directory in bytes.
Get the disk usage of a given directory .