检索文件夹大小

时间:2013-03-13 23:51:45

标签: php

我需要在mysql表上检索每日文件夹大小和存储值。 我用cronjob来调用php文件。

Wich方法更好,使用linux风格:

$output = `du -s $folder`;

或使用这样的功能?

  function getDirectorySize($path) 
{ 
$totalsize = 0; 
$totalcount = 0; 
$dircount = 0; 
if ($handle = opendir ($path)) 
{ 
  while (false !== ($file = readdir($handle))) 
  { 
    $nextpath = $path . '/' . $file; 
    if ($file != '.' && $file != '..' && !is_link ($nextpath)) 
    { 
      if (is_dir ($nextpath)) 
      { 
        $dircount++; 
        $result = getDirectorySize($nextpath); 
        $totalsize += $result['size']; 
        $totalcount += $result['count']; 
        $dircount += $result['dircount']; 
      } 
      elseif (is_file ($nextpath)) 
      { 
        $totalsize += filesize ($nextpath); 
        $totalcount++; 
      } 
    } 
  } 
} 
closedir ($handle); 
$total['size'] = $totalsize; 
$total['count'] = $totalcount; 
$total['dircount'] = $dircount; 
return $total; 
} 

0 个答案:

没有答案