本文整理匯總了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;
}