<?php
/*
   *************************************************************************
   * Combien que j'en ai ? Un script fait à la main par mes doigts dans    *
   * mon VI que j'ai.                                                      *
   *                                                                       *
   * Pour toute information sur le fonctionnement du script : lisez la doc *
   * sur http://www.php.net/ (ça dégourdit les synapses)                   *
   * Copyright rien du tout, Script sous DemerdenSieSich License...        *
   *                                                                       *
   * Vous pouvez copier/modifier/utiliser/warezer/napsteriser ce script si *
   * vous le souhaitez. Par contre, je ne peux etre tenu pour repsonsable  *
   * de ce que vous en faites. Et voilà :)                                 *
   *************************************************************************
*/

$ls_result = <<<EOT
<html>
 <head><title>Espace Disque Utilisé</title></head>
 <body>
  Le répertoire 
{CHEMIN} utilise {TOTAL}B / {TOTALK}KiB / {TOTALM}MiB<br/>
  <br/>
  Fichiers : 
{FILES} - Directory : {DIRS}<br/>
  <br/>
  <a href="
{URL}">Recompter</a>
 </body>
</html>
EOT;

$ls_error = <<<EOT
<html>
 <head><title>Espace Disque Utilisé</title></head>
 <body>
  Impossible d''accéder au répertoire 
{CHEMIN}<br/>
  <br/>
  <a href="
{URL}">Same player try again</a>
 </body>
</html>
EOT;

$ls_path_def $_SERVER["DOCUMENT_ROOT"];
$ls_result=ereg_replace("\{URL\}"$_SERVER["PHP_SELF"], $ls_result);
$ls_result=ereg_replace("\{CHEMIN\}"$ls_path_def$ls_result);
$ls_error=ereg_replace("\{URL\}"$_SERVER["PHP_SELF"], $ls_error);
$ls_error=ereg_replace("\{CHEMIN\}"$ls_path_def$ls_error);

# Aucun interet en fait, mais l'habitude ...
clearstatcache();
# c'est porcasse, mais pas le temps
$gi_f 0;
$gi_d 0;
$gi_s 0;

function 
mondirquipue($as_dir,&$f, &$d, &$s) {
  global 
$gi_f$gi_d$gi_s;
  if (
$lo_hl=@opendir($as_dir)) {
    while (
false !== ($ls_f readdir($lo_hl))) {
      if (
$ls_f != "." && $ls_f != "..") {
        if (
$lo_t=@opendir($as_dir.$ls_f."/")) {
          
closedir($lo_t);
          
$d++;
          if (!
is_link($as_dir.$ls_f))
            
mondirquipue($as_dir.$ls_f."/"$f$d$s);
        }
        else {
          
$f++;
          if(
$lt_f=@stat($as_dir.$ls_f))
            
$s+=$lt_f["size"];
        }
      }
    }
    
closedir($lo_hl);
  }
}

if (
$lo_hl=@opendir($ls_path_def)) {
  
closedir($lo_hl);
  
mondirquipue(substr($ls_path_def, -1)=="/"?$ls_path_def:$ls_path_def."/"$gi_f$gi_d$gi_s);
  
$ls_result=ereg_replace("\{FILES\}",  (string)$gi_f$ls_result);
  
$ls_result=ereg_replace("\{DIRS\}",   (string)$gi_d$ls_result);
  
$ls_result=ereg_replace("\{TOTAL\}",  (string)$gi_s$ls_result);
  
$ls_result=ereg_replace("\{TOTALK\}", (string)(round(($gi_s/1024),2)), $ls_result);
  
$ls_result=ereg_replace("\{TOTALM\}", (string)(round(($gi_s/(1024*1024)),2)), $ls_result);
  print 
$ls_result;
  exit;
}
else {
  print 
$ls_error;
  exit;
}

?>