Monday 19 September 2016

PHP Function to List Files From Directory

PHP function to list the files in the given path. List files from a directory with this php functions as link, so that you can open the files in new tabs.

function listFiles($path) {
    if(is_dir($path)) {
          if($handle = opendir($path)) {
              while(($file = readdir($handle)) !== false) {
                  if($file != "." && $file != ".." && $file != "Thumbs.db") {
                      echo '<a target="_blank" href="'.$path.$file.'">'.$file.'</a><br>'."\n";
                  }
              }
              closedir($handle);
          }
    }
}

No comments:

Post a Comment