Punit Thanki Punit Thanki - 1 year ago 153
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 Source

function listFolderFiles($dir){
   $fileFolderList = scandir($dir);
   echo '<ul>';
   foreach($fileFolderList as $fileFolder){
       if($fileFolder != '.' && $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/) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download