0
  • How to display all files and folders available in current directory php (FTP)
  • See Attached image example....

Tree View Image

1 Answer 1

3
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/) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.