Use the following PHP code snippet to list all files and folders in a directory
- function list_files($dir)
- {
- if(is_dir($dir))
- {
- if($handle = opendir ($dir))
- {
- while(($file = readdir($handle)) !== false)
- {
- if($file != "." && $file != ".." & ;& $file != "Thumbs.db"/*pesky windows, images..*/)
- {
- echo '
'."n";
- }
- }
- closedir($handle);
- }
- }
- }
Copy code
Usage:
- list_files("images/"); //This will list all files of images folder
- ?>
Copy code
|