Home >Backend Development >PHP Tutorial >How to List Directory Files in PHP using `scandir()`?
How to List Directory Files in PHP
Question:
How can you list all the files in a specific directory using PHP?
Answer:
The scandir() function provides a convenient way to list files in a directory. For example, the following code retrieves a list of files from the usernames directory:
$path = '/path/to/usernames'; $files = scandir($path);
Additional Considerations:
$files = array_diff(scandir($path), array('.', '..'));
The above is the detailed content of How to List Directory Files in PHP using `scandir()`?. For more information, please follow other related articles on the PHP Chinese website!