How do you get all the files from the directory in PHP?

1 answer

Answer

1085190

2026-05-06 06:35

+ Follow

To list all the files in a directory you would use the following: $handle = opendir('/path/to/folder');

while(($file = readdir($handle)) !== false){

// do things with files

// you will want to filter out things like ., .., and .htaccess

echo $file;

}

Also, to return a list of all the files in a directory, especially with wildcards, use something such as:

$file_array = glob("*"); $files = implode("\n", $file_array);

echo $files;

will give you a list of all the files directly.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.