Want to show Directory Tree of server (PHP) at client side using FLEX? -


using recursivedirectoryiterator of php able create directory tree , can flatten using recursiveiteratoriterator class , want create directory tree structure tree component of flex understands . following array structure in php flex understands.

array('label'=>'rootdirectory','children'=>array(array('label'=>'subfolder1','children'=>array(array('label'=>'file.jpg'))),array('label'=>'emtptyfolder','children'=>array()))); 

please show me way create whole directory structure @ server side above array format. in advance !!

you may adjust code needs. not copy & paste solution needed different usecase, should @ least halfway implementing own solution it. key lies in adjusting methods recursiveiteratoriterator call when traversing directory tree.

<?php /** * prints directory structure nested array * * iterator can used wrap recursivedirectoryiterator output * files , directories in parseable array notation. because iterator * print array during iteration, output has buffered in * order captured variable. * * <code> * $iterator = new recursivedirectoryasnestedarrayformatter( *     new recursivedirectoryiterator('/path/to/a/directory'), *     recursiveiteratoriterator::self_first * ); * ob_start(); * foreach($iterator $output) echo $output; * $output = ob_get_clean(); * </code> * */ class recursivedirectoryasnestedarrayformatter extends recursiveiteratoriterator {     /**      * prints 1 tab stop per current depth      * @return void      */     protected function indent()     {         echo str_repeat("\t", $this->getdepth());     }     /**      * prints new array declaration      * return void      */     public function beginiteration()     {         echo 'array(', php_eol;     }     /**      * prints closing bracket , semicolon      * @return void      */     public function enditeration()     {         echo ');', php_eol;     }     /**      * prints indented subarray key being current directory name      * @return void      */     public function beginchildren()     {         $this->indent();         printf(             '"%s" => array(%s',             basename(dirname($this->getinneriterator()->key())),             php_eol         );     }     /**      * prints closing bracket , comma      * @return void      */     public function endchildren()     {         echo '),', php_eol;     }     /**      * prints indented current filename , comma      * @return void      */     public function current()     {         if ($this->getinneriterator()->current()->isfile()) {             printf(                 '%s"%s",%s',                 str_repeat("\t", $this->getdepth() +1),                 $this->getinneriterator()->current()->getbasename(),                 php_eol             );         }     } } 


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -