How to view all files in a directory using php.

With PHP version 5.0 and higher, you can apply a function called dir_scan() to return all the filenames in a directory.

$dir    = ‘dir_scan_test/’;
$files1 = scandir($dir);
print_r($files1);
The list of filenames will be in an array.

With PHP version 4.0 and lower, you have to use opendir($path) function to retrieve a list of files


So, compared to PHP4, applying PHP5 codes will be much cleaner and therefore your scripts will be executed faster.