Beispiel #1
0
 function sfGetDirSize($dir)
 {
     if (file_exists($dir)) {
         // ディレクトリの場合下層ファイルの総量を取得
         if (is_dir($dir)) {
             $handle = opendir($dir);
             while ($file = readdir($handle)) {
                 // 行末の/を取り除く
                 $dir = ereg_replace("/\$", "", $dir);
                 $path = $dir . "/" . $file;
                 if ($file != '..' && $file != '.' && !is_dir($path)) {
                     $bytes += filesize($path);
                 } else {
                     if (is_dir($path) && $file != '..' && $file != '.') {
                         // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。
                         $bytes += SC_Utils::sfGetDirSize($path);
                     }
                 }
             }
         } else {
             // ファイルの場合
             $bytes = filesize($dir);
         }
     }
     // ディレクトリ(ファイル)が存在しない場合は0byteを返す
     if ($bytes == "") {
         $bytes = 0;
     }
     return $bytes;
 }