I am trying to get thumbnails of images that reside in more than one directory.
I have the directories names in an array.
Right now I get the images from the directories, but for each dir the script returns the file names in all of the previous directories as well as the file names in the current directory.
How do I stop getting the image names from the previous directories?
function show_img($file,$key,$dir)
{
echo "<img src='$dir/$file'><br/>\n";
}
$animals = array('dog','cat','monkey');
$dirFiles = array();
for ( $n=0; $n<count($animals); $n++ )
{
echo "<h1 style>".$animals[$n]."</h1>";
if ( $handle = opendir($animals[$n]) )
{
while ( false !== ( $file = readdir($handle)) )
{
if ( $file != "." && $file != ".." && preg_match("/jpe*g$|gif$/",$file))
{
$dirFiles[] = $file;
}
}
closedir($handle);
}
array_walk($dirFiles,'show_img',$animals[$n]);
}