
The next if statement opens the directory if it is in fact a directory. The is_dir()įunction checks to make sure that this pathway is a directory. The next line is an if statement that makes sure that the pathway you specified is a directory.

If you want to list all the files in the Files directory, you would set directory equal to "Files/" If you want to list all the files in the images directory, you would set directory equal to "Images/" This, again, is if you want to list all the files in the Toys directory. Most of the time, however, "Toys/" would be the correct setup. Since we want the files listed in the Toys directory, we set the directory equal to "Toys/"ĭepending on your website set up, based on the current directory you are in, you may have to set the directoryĮqual to "/Toys". So the first line specifies the path to the directory, whose file contents we want to find.
#Php list directory contents recursive code#
We'll now explain the code of how this is done. You can see how every file in the Toys directory is listed below. The PHP code above displays all the files in the Toys directory. The PHP code needed to show all files in a directory is shown below. So now we will go into the code required to display all files in a directory. So PHP is pretty efficient at looking and obtaining files you may need for any directory on your website. You have access to all the files and see if you right click on the link, you can save it to the computer. So this form above can kind of be seen as an FTP on the cloud that you can access from your own website.

This is actually really much like an file transfer protocol (FTP), which allows you see all files in all directories of your website. So by clicking the link, you can see the contents inside all the files. If you enter in "Toys" or "Vacations" and press the 'Submit' button, you will see all files for the associated directories.Īnd the form above is made so that links are created for all the files in the directories. The above HTML form allows you to see the Toys directory or the Vacations directory of this website.

#Php list directory contents recursive how to#
In this article, we show how to show all files in a directory of a website using PHP. How to List All Files of a Directory Using PHPĮnter a Directory: Enter Toys or Vacations directory
