Given the path of the folder and the task is to print names of subfolders and files present inside them.
Explaination: In our PHP code, initially, it is checked whether provided path or filename is a directory or not using is_dir() function. Now, we open the directory using opendir() function and then checking whether it is getting opened or have some errors. Then we use a while loop to get names of all the subfolders, as well as files, present inside the directory with the help of readdir() function. Now we are going inside each subfolder and reading the names of all the files present inside them following a similar procedure.
Note: This Code have been saved as PHP file and accessed through wampserver
- Copy the entire contents of a directory to another directory in PHP
- How to include() all PHP files from a directory ?
- How to count files in a directory using PHP?
- How to display all files in a directory using Node.js ?
- How to recursively delete a directory and its entire contents (files + sub dirs) in PHP?
- How to keep compiled files in a separate directory ?
- How to see the changes in whole directory/folder containing many sass files ?
- PHP | dir() (Get instance of the Directory)
- How to copy a file from one directory to another using PHP ?
- Deleting all files from a folder using PHP
- How to create directory with HTML button and PHP ?
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- Which characters are valid in CSS class names/selectors?
- How to Zip a directory in PHP?
- Why PHP script does not create a directory with 777 permissions ?
- How to open a PDF files in web browser using PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.