recurse_dirsize()

递归地获取目录的大小。

recurse_dirsize( string $directory , string|array $exclude = null, int $max_execution_time = null )

说明(Description)

当目录包含其他目录时,由get-dirsize()用于获取该目录的大小。


参数(Parameters)

参数类型必填说明
$directory(string)必需目录的完整路径。
$exclude(string | array)可选要从路径总数或路径数组中排除的子目录的完整路径。应为不带尾随斜杠的。
$max_execution_time(int)可选放弃前的最长跑步时间。几秒钟后。超时是全局的,从WordPress开始加载时开始测量。

返回(Return)

(int|false|null)有效目录的字节大小。如果不是,就错了。如果超时,则为空。


源码(Source)

/**
 * Get the size of a directory recursively.
 *
 * Used by get_dirsize() to get a directory's size when it contains
 * other directories.
 *
 * @since MU
 * @since 4.3.0 $exclude parameter added.
 *
 * @param string $directory Full path of a directory.
 * @param string $exclude   Optional. Full path of a subdirectory to exclude from the total.
 * @return int|false Size in MB if a valid directory. False if not.
 */
function recurse_dirsize( $directory, $exclude = null ) {
	$size = 0;
	$directory = untrailingslashit( $directory );
	if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude ) {
		return false;
	}
	if ($handle = opendir($directory)) {
		while(($file = readdir($handle)) !== false) {
			$path = $directory.'/'.$file;
			if ($file != '.' && $file != '..') {
				if (is_file($path)) {
					$size += filesize($path);
				} elseif (is_dir($path)) {
					$handlesize = recurse_dirsize( $path, $exclude );
					if ($handlesize > 0)
						$size += $handlesize;
				}
			}
		}
		closedir($handle);
	}
	return $size;
}
更新版本源码位置使用被使用
MU (3.0.0)wp-includes/functions.php:750032
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索