I can't remember where I found this but it's useful.
You just parse directory and the file extensions you want to include and it'll store the filenames in an array.
function directory($dir,$filters)
{
$handle=opendir($dir);
$files=array();
if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
if ($filters != "all")
{
$filters=explode(",",$filters);
while (($file = readdir($handle))!==false)
{
for ($f=0;$f<sizeof($filters);$f++):
$system=explode(".",$file);
if ($system[1] == $filters[$f]){$files[] = $file;}
endfor;
}
}
closedir($handle);
return $files;
}
You could then use:
$filenames = directory(".", "jpg") //for multiple file types just separate the file extensions by commas
foreach ($filenames as $value)
{
echo "<tr><td>$value</td><td><img border=\"0\" src=$value width=\"25%\"></td></tr>";
}