Posted By

apphp-snippets on 02/24/13


Tagged

php content directory


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Abiotic


List Directory Contents in PHP


 / Published in: PHP
 

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

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

  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. ?>

Report this snippet  

You need to login to post a comment.