Here's what I use:
##########################################
# Returns list of images
##########################################
function GetFileList($dirname) {
$files = array();
$dir = opendir( $dirname );
while( $file = readdir( $dir ) )
{
if (eregi("\.jpe?g$", $file) || eregi("\.gif$", $file) || eregi("\.png$", $file))
{
$files[] = $file;
}
}
rsort($files);
return $files;
}
To call it, just do:
$imagelist = GetFileList($path);
And to cycle through the results:
foreach($imagelist as $image)
{
// do stuff
}