Get the Size of a Folder





24
Date Submitted Fri. Oct. 14th, 2005 5:12 PM
Revision 1 of 1
Helper lilleman
Tags Folder | PHP | Size
Comments 1 comments
Get the Size of a Folde
<?php
 
function dirsize($folder)
{
  if( !is_dir($folder) ): return -1; endif;
 
  $handle = opendir($folder); $dirsize = 0;
  $folder = preg_replace('/(\/|\\\\)+$/', '', $folder).'/';
 
  while(($currentItem = readdir($handle)) !== false)
  {
    if(( $currentItem != '.' ) && ( $currentItem != '..' ))
    {
      $function = is_dir($folder.$currentItem) ? 'dirsize' : 'filesize';
      $dirsize += call_user_func($function, $folder.$currentItem);
    }
  }
 
  return $dirsize;
}
 
?>

Erik Riklund

phofer.com

Comments

Comments hmmm...
Sun. Aug. 20th, 2006 10:28 AM    Newbie dedos

Voting