J'aimerai avoir des explications sur la classe DirectoryTreeIterator.
1. ou puis je télécharger la classe complete car je n'ai trouvé que ceci (mais peut être est-ce suffisant ??) :
class DirectoryTreeIterator extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new RecursiveCachingIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_FILENAME), CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD), 1);
}
function current()
{
$tree = '';
for ($l=0; $l < $this->getDepth(); $l++) {
$tree .= $this->getSubIterator($l)->hasNext() ? '| ' : ' ';
}
return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-')
. $this->getSubIterator($l)->__toString();
}
function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func), $params);
}
}
2. Comment marche la classe?? Voici le code que j'utilise mais impossible d'afficher un arbre(tree) des fichiers et dossiers.
$path = realpath('/home/xxx/www/test');
//$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
$objects = new DirectoryTreeIterator($path);
foreach($objects as $name => $object){
echo "$name\n";
}
Ca maffiche les données comme ceci : Alors que ca devrait me donner un truc du genre (ne pas faire attention aux noms des fichiers et dossiers => c'est un exemple) :favicon.ico medias banners banner2.swf banner.png banner.swf images icon-plusmoins.png playlist.png videopreview.jpg icon-user_annonceur.png full_top.gif icon-refresh.png icon-view13.png icon-plus32.png fleche.png icon-photos.png icon-download13.png watermark_medium.png default_picture.png icon-help.png watermark_big.png icon-place.png highslide loader.gif geckodimmer.png close.png zoomin.cur controlbar4.gif
|-ch01
| |-recipe01
| | |-example01.php
| | \-example02.php
| |-recipe02
| | |-example01.php
| | \-example02.php
| |-recipe03
| | \-example01.php
Merci pour votre aide,
raph