The below code shows you how to get a list of all file in a directory/folder using PHP.
$listOfFiles = scandir('your-directory'); $listOfFiles = array_diff($listOfFiles , array('.', '..'));
We firstly use
scandir function to get a list of files of the specified directory. But in the result of this function, there are two values (
..), which are not a file. So in order to remove these values, we simply use
array_diff as shown right above.