Calculate the size for a directory : Directory : File Directory PHP Source Code


PHP Source Code » File Directory » Directory »

 

Calculate the size for a directory




<?php
   function directory_size($directory) {
      $directorySize=0;
      if ($dh = @opendir($directory)) {
         while (($filename = readdir ($dh))) {
           if ($filename != "." && $filename != "..") {
             if (is_file($directory."/".$filename)){
                $directorySize += filesize($directory."/".$filename);
             }   
             if (is_dir($directory."/".$filename)){
                $directorySize += directory_size($directory."/".$filename);
             }
           }
        }
      }
      @closedir($dh);
      return $directorySize;
  }

   $directory = "./";
   $totalSize = round((directory_size($directory1024)2);
   echo "Directory $directory: ".$totalSize. "kb.";

?>

           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo File Directory
» Directory