Heim >Backend-Entwicklung >PHP-Tutorial >一个统计目录文件大小的php函数_PHP教程

一个统计目录文件大小的php函数_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:39:351042Durchsuche

  1.    
  2. /** 
  3.   统计目录文件大小的函数 
  4.   @author xfcode 
  5.   @link http://www.jbxue.com 
  6. */  
  7.  function dirsize($dir)  
  8.  {  
  9.    @$dh = opendir($dir);  
  10.    $size = 0;  
  11.    while ($file = @readdir($dh))  
  12.   {  
  13.     if ($file != "." and $file != "..")  
  14.    {  
  15.      $path = $dir."/".$file;  
  16.       if (is_dir($path))  
  17.      {  
  18.        $size += dirsize($path);  
  19.       }  
  20.      elseif (is_file($path))  
  21.      {  
  22.        $size += filesize($path);  
  23.       }  
  24.     }  
  25.    }  
  26.   @closedir($dh);  
  27.   return $size;  
  28.  }  
  29. //function end   
  30.   
  31. //eg:  
  32.  $dir_path = "./my_files";  
  33.  $dir_size = dirsize($dir_path);  
  34.  $dir_size = $dir_size/1024/1024;  
  35.  echo $dir_size."MB";  
  36.  ?>  

这个函数可以递归遍历目录中的所有文件,并计算以MB为单位的文件总大小。 
新手出招,大佬们见笑了。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/729851.htmlTechArticle? /** 统计目录文件大小的函数 @authorxfcode @linkhttp://www.jbxue.com */ functiondirsize($dir) { @$dh =opendir($dir); $size= 0 ; while ($file= @readdir ($dh)) { if ($file...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn