PHP: Get Folder Size & File Count

Here is a little PHP code you can use to get the size and file count of an entire directory including sub-directories

$filename){
  if($filename!=".." && $filename!="."){
   if(is_dir($dir."/".$filename)){
    $new_foldersize = foldersize($dir."/".$filename);
    $count_size = $count_size + $new_foldersize[0];
    $count = $count + $new_foldersize[1];
   }else if(is_file($dir."/".$filename)){
    $count_size = $count_size + filesize($dir."/".$filename);
    $count++;
   }
  }
  
 }
 
 return array($count_size,$count);
}

$sample = foldersize("SAMPLE_DIRECTORY");

echo "Folder Size : " . $sample[0] . " Bytes 
" ; echo "File Count : " . $sample[1] . " Files " ; ?>