Get a directory listing.


/ Published in: PHP
Save to your folder(s)

List files within a directory while ignoring system folders such as "Thumbs.db" as well as "." and "..".


Copy this code and paste it in your HTML
  1. <?php
  2. function listFiles($dir)
  3. {
  4. if(is_dir($dir)){
  5. if($handle = opendir($dir)){
  6. while(($file = readdir($handle)) !== false){
  7. if($file != "." &amp;&amp; $file != ".." &amp;&amp; $file != "Thumbs.db"{
  8. echo '<a target="_blank" href="'.$dir.$file.'">'.$file.'</a><br/>'."\n";
  9. }
  10. }
  11. closedir($handle);
  12. }
  13. }
  14. }
  15.  
  16. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.