1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| <?php
class Dossier
{
var $maison;
var $nom;
var $chemin;
var $open = false;
var $select = false;
var $liste_dossiers = array();
var $liste_fichiers = array();
/**
Constructeur
@PARAM $chemin_absolut
@PARAM $maison
@RETURN : Un objet de la classe Dossier
*/
function Dossier($chemin_absolut, $maison)//constructeur
{
echo "<br/>Dossier(".$chemin_absolut.")";
$this->maison = $maison;
$this->chemin = $chemin_absolut;
$tab = explode("/", $chemin_absolut);
$nb = (count($tab));
$this -> nom = $tab[($nb-1)];
return $this;
}
/**
$ret = Dossier demander.
$chemin = chemin absolut de la position de la cible dans l'arbre
$profondeur = profondeur actuelle dans l'arbo
*/
function &go($chemin, $profondeur = 0)
{
echo "<br/>go(".$chemin.", ".$profondeur.")";
$tab = explode("/", $chemin);
$nb = (count($tab));
if($nb-1 == $profondeur)
{
//on est arrivé.
//mais on vérifit quand même
if ($tab[$profondeur] !== $this->nom)
{
echo "<br/>erreur : nous devrion étre dans ".$tab[$profondeur]." et nous somme dans ".$this->nom;
}
return $this;
}
else
{
//on est dans :
$actu = $tab[$profondeur];
//et on le vérifit (' ,)
if ($actu !==$this->nom)
{
echo "<br/>erreur : nous devrion étre dans ".$actu." et nous somme dans ".$this->nom;
}
//on poursuit notre chemin
$profondeur++;
//dans
$nom_dossier_suivant = $tab[$profondeur];
$dossier_suivant =& $this->get_dossier($nom_dossier_suivant);
//on se place dans le dommaine d'exécution du répertoire suivant
return $dossier_suivant -> go($chemin, $profondeur);
}
}
/**
retourne le dossier $nom de la liste des dossiers
*/
function &get_dossier($nom)
{
echo "<br/>get_dossier(".$nom.")";
for($i = 0; $i<count($this->liste_dossiers) ; $i++)
{
$d = $this->liste_dossiers[$i];
$nom_d = $d->nom;
if($nom_d == $nom)
{
return $d;
}
}
echo "<br/>erreur le fichier ".$nom." n'as pas été trouvé";
return false;
}
function ouvrir()
{
$this->open = true;
echo "<br/>ouvrir() this = ".$this->nom." ouver = ".$this->open;
$this -> explore_dossier();
}
function ferme()
{
$this->open = false;
}
/**
La fonction explore dans le context du dossier courant dans l'arborescence le contenu physique du dossier sur le disque.
Tout les dossiers trouvé (sauf '' , '.' , '..') sont ajouté à la liste des dossier : $liste_dossiers.
WARNNING C'est fonction fonctionne différament sous Windows et UNIX.
la fonction utilise les attibuts de sa classe : $this->maison, $this->chemin
WARNNING la définition initiale de $this->maison dépend de l'implémentation du site sur le serveur.
*/
function explore_dossier()
{
$ici_unix = $this->maison."/".$this->chemin;
$ici_windows = str_replace('/', '\\', $ici_unix) ;
//$ici_windows = ".\\USERS\\toto";
echo "<br/>explore_dossier() ici_unix = ".$ici_unix." ici_windows = ".$ici_windows ;
if ($handle = opendir($ici_windows))
{
//echo "<br/>";print_r ($this->liste_dossiers);echo "<br/>";
while (false !== ($obj = readdir($handle)))
{
if($obj != '..' && $obj !='.' && $obj !='')
{
if (is_dir($obj) || 1)// WARNNING WINDOWS TOUCHHH
{
$this->liste_dossiers[] = new Dossier($this->chemin."/".$obj, $this->maison);
}
}
}
closedir($handle);
//echo "<br/>";print_r ($this->liste_dossiers);echo "<br/>";
}
clearstatcache();
}
function toHTML() { }
function afficher_fichiers() { }
function toString($profondeur = 0)
{
echo "<br/> toString(".$profondeur.") this = ".$this->nom." ";
$ret ="<br/>";
for($i=0 ; $i<$profondeur ; $i++){$ret .=" _ ";}
$ret .= "nom = ".$this->nom." | chemin = ".$this->chemin." | ouver = ".$this->open." | selectionne = ".$this->select."" ;
$nb = count($this->liste_dossiers);
echo " nb = ".$nb." ";
for ( $i=0 ; $i<$nb ; $i++ )
{
$next_step = $this->liste_dossiers[$i];
$ret .= $next_step->toString($profondeur+1);
}
return $ret;
}
}//fin de la class dossier.
?> |
Partager