have written a class that uses in built php function DirectoryIterator which as to show folder structure like this
root
   |__subfolder
   |          |_mp3 
   |          |_png
   |__subfolder2
              |_mp3
              |_mp3 
Here is my class
 <?php
  $list = array();
 $dir = new DirectoryIterator('/opt/lampp');
 foreach ($dir as $fileinfo)
 {
 if ($fileinfo->isFile())
  {
    //echo $fileinfo->getBasename() . "\n";
   //echo $fileinfo->getBasename('.jpg') . "\n";
  }
  else
   { //create object with two fields
            $list3 = array( 'name'=> $fileinfo->getFilename(),
                            'type'=> $fileinfo->getType(),
                            'date'=> $fileinfo->getMTime(),
                            'size'=> $fileinfo->getSize());
             array_push($list, $list3);
    }
        $return_array = array('files'=>$list);
        echo json_encode(  $return_array)
     }
     ?>
have written the echo json_encode but the string format does not seem to be correctly writen
here is a view of the string format of the out put, am using online json viewer for verification
 {"files":[{"name":"info","type":"dir","date":1491647493,"size":4096}]}     {"files":[{"name":"info","type":"dir","date":1491647493,"size":4096},{"name":"pear","type":"dir","date":1491647422,"size":4096}]}{"files":[{"name":"info","type":"dir","date":1491647493,"size":4096},{"name":"pear","type":"dir","date":1491647422,"size":4096},
 
     
    