当前位置: 首页>>代码示例>>PHP>>正文


PHP recurse_dirsize函数代码示例

本文整理汇总了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;
}
开发者ID:Jitsufreak,项目名称:PJ,代码行数:38,代码来源:ms-functions.php

示例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;
}
开发者ID:nhemsley,项目名称:wordpress,代码行数:38,代码来源:ms-functions.php

示例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;
 }
开发者ID:Offirmo,项目名称:base-wordpress,代码行数:10,代码来源:class-dashboard-directory-size-common.php


注:本文中的recurse_dirsize函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。