Punit Thanki Punit Thanki - 1 month ago 24
jQuery Question

TreeView directory structure in php


  • How to display all files and folders available in current directory php (FTP)

  • See Attached image example....



Tree View Image

Answer
define('SITE_URL',"http://yourdomain.com");

function listFolderFiles($dir){
   $fileFolderList = scandir($dir);
   echo '<ul>';
   foreach($fileFolderList as $fileFolder){
       if($fileFolder != '.' && $fileFolder != '..'){
           if(!is_dir($dir.'/'.$fileFolder)){
               echo '<li><a target="_blank" href="'.SITE_URL.'/'.ltrim($dir.'/'.$fileFolder,'./').'">'.$fileFolder.'</a>';
           } else {
               echo '<li>'.$fileFolder;
           }
           if(is_dir($dir.'/'.$fileFolder)) listFolderFiles($dir.'/'.$fileFolder);
               echo '</li>';
           }
   }
   echo '</ul>';
}
listFolderFiles('uploads/'); // function call with directory path (e.g. : upload/)