Home > Backend Development > PHP Tutorial > PHP lists all files and folders in a directory

PHP lists all files and folders in a directory

WBOY
Release: 2016-07-25 08:42:44
Original
1067 people have browsed it

Use the following PHP code snippet to list all files and folders in a directory

  1. function list_files($dir)
  2. {
  3. if(is_dir($dir))
  4. {
  5. if($handle = opendir ($dir))
  6. {
  7. while(($file = readdir($handle)) !== false)
  8. {
  9. if($file != "." && $file != ".." & ;& $file != "Thumbs.db"/*pesky windows, images..*/)
  10. {
  11. echo '
    '."n";
  12. }
  13. }
  14. closedir($handle);
  15. }
  16. }
  17. }
Copy code

Usage:

  1. list_files("images/"); //This will list all files of images folder
  2. ?>
Copy code

PHP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template