PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have this function which if $type = 0, then it lists all the directories in a specified folder. If $type = 1 then it lists all the dirs in the specified folder that have image files within them.
The problem is that when I use type =1. I have 2 images in folder 1 and 1 image in folder 2. So the script puts folder 1 into the $dir_list array 4 times. And the script puts folder 2 into the array 2 times.
What is causing the extra insertions.
$pics == 0;
while(false !== ($file = readdir($handle))){
if ($pics == 1){
break;//if an image is found in a folder; dont search for further images
}
for($i=0;$i<sizeof($ext);$i++) {
if(strstr($file, ".".$ext[$i])) {
$dir_list[] = $dir;
$pics = '1';
break; //if found, dont search for other extensions
}
}
}
$count = 0;//count the number of times files matched.
while(false !== ($file = readdir($handle))){
if ($pics == 1){
break;//if an image is found in a folder; dont search for further images
}
for($i=0;$i<sizeof($ext);$i++) {
if(strstr($file, ".".$ext[$i])) {
echo $file."<br />";
//if(!in_array($dir_list)) $dir_list[] = $dir; //if you can't find the problem use this line
dir_list[] = $dir; //if you uncomment the above line, then comment this line
echo $count++."<br />";
$pics == 1;
break; //if found, dont search for other extensions
}
}
}