Can anyone help me out, I posted a message about directory listing a week ago and have done a little bit more work on it.
Basically I want to only list named directories and display an image if a specified image is found.
When I've ran the code, it doesn't seem to like it when I use if(file_exists)
I have used if(!file_exists) to test it out and it displays the images properly so it is nothing to do with paths etc.
Anyone any ideas, or suggestions to tidy my code up?
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$test = filetype($dir . $file);
if($test == "dir") # check it is a directory
if(($file != ".") && ($file != "..")){ # do not list the base directory elements
$image = strtolower($file)."_main.jpg"; # convert file to lowercase and append to image variable
if(file_exists($image)){ # check if a main image exists, if so display the directory
echo "<img src=media/pics/".$name."/".$file."/".$image. ">";
echo $file ."<br>";
} else {
echo "no match";
}
}
}
}
closedir($dh);
}