PHP5: Calculer la taille d’un Répertoire

Author:


Download


<?php
class maClasse
{
  static function  taille_repertoire($repertoire)
   {
      $taille_rep=0;
      if ($dI = @opendir($repertoire))
      {
         while (($nom_fichier = readdir ($dI)))
         {
           if ($nom_fichier != "." && $nom_fichier != "..")
           {
             if (is_file($repertoire."/".$nom_fichier))
             {
                $taille_rep += filesize($repertoire."/".$nom_fichier);
             }
             if (is_dir($repertoire."/".$nom_fichier)){
                $taille_rep += taille_repertoire($repertoire."/".$nom_fichier);
             }
           }
        }
      }
      @closedir($dI);
      return $taille_rep;
  }
}
   $repertoire = "./";
   $taille = round((maClasse::taille_repertoire($repertoire) / 1024), 2);
   echo "Taille du repertoire $repertoire: ".$taille. "kb.";

?>

Leave a Reply

Your email address will not be published. Required fields are marked *


+ five = 10