PHP

How to Get All Files in a Directory in PHP2 min read

In this example,I will show you how to how to get all files in a folder using PHP Language. You can esay and simply get list of files in Folder in PHP.

We use the built-in function scandir() to take files name from a directory.




The scandir() function lists the files and directories names which are present inside a specified path.

scandir():The scandir() function in PHP is an inbuilt function which is used to return an array of files and directories of the specified directory.

Example 1:

Output:

Example 2:

Output:

Example 3: Php list all files in directory recursively

Output:

Example 4: Get File names form Current Directory

Output:

Example 5: Get file name from directory

Output:

Leave a Comment