Check out the manual section on directory functions. This is a modified example from the manual:
give get_image_list a directory and it will return an array containing the names of all of the images in that directory in an array.
function get_image_list($directory) {
$files = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
$extension = strtolower(strrchr($file, "."));
if ($file != "." && $file != ".." && ($extension == ".png" || $extension == ".jpg" || $extension == ".gif")) {
$files[] = $file;
}
}
closedir($handle);
}
return($files);
}