本文整理汇总了PHP中recurse_dirsize函数的典型用法代码示例。如果您正苦于以下问题:PHP recurse_dirsize函数的具体用法?PHP recurse_dirsize怎么用?PHP recurse_dirsize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了recurse_dirsize函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recurse_dirsize
/**
* 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;
}
示例2: recurse_dirsize
/**
* Get the size of a directory recursively.
*
* Used by get_dirsize() to get a directory's size when it contains
* other directories.
*
* @since MU
*
* @param string $directory
* @return int
*/
function recurse_dirsize($directory)
{
$size = 0;
if (substr($directory, -1) == '/') {
$directory = substr($directory, 0, -1);
}
if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
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);
if ($handlesize > 0) {
$size += $handlesize;
}
}
}
}
closedir($handle);
}
return $size;
}
示例3: filter_get_directory_size
public function filter_get_directory_size($size, $path)
{
require_once ABSPATH . 'wp-includes/ms-functions.php';
if (!is_dir($path)) {
$size = -1;
} else {
$size = recurse_dirsize($path);
}
return $size;
}