List items in directory


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

Prints out the contents of a directory.


Copy this code and paste it in your HTML
  1. $dir = ".";
  2.  
  3. if( is_dir( $dir ) ){
  4. if( $dir_handle = opendir( $dir ) ){
  5. while( $filename = readdir( $dir_handle ) ){
  6. echo "filename: {$filename}<br />" ;
  7. }
  8. //rewinddir($dir_handle) to start over
  9. closedir( $dir_handle );
  10. }
  11. }
  12.  
  13. echo "<hr />";
  14.  
  15. if( is_dir( $dir ) ){
  16. $dir_array = scandir( $dir );
  17. foreach( $dir_array as $file ){
  18. if( stripos( $file, '.' ) > 0){
  19. echo "filename: {$file}<br />";
  20. }
  21. }
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.