當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。