List Directory Contents in PHP


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

This code allows to list the contents of any given directory.


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

URL: http://www.apphp.com/index.php?snippet=php-list-directory-contents

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.