MikeDXUNL Posted November 25, 2008 Share Posted November 25, 2008 list of directories and subs: + photos |---+ BAND EVENT 1 | |---gearsbg.jpg | |---+ BAND EVENT 2 | |--- brownsbg1.jpg | |--- halobg1.jpg | |------ gearsbg.jpg |------ halobg1.jpg |------ brownsbg1.jpg (see attached file if you don't understand.) <?php $path = 'photos/'; if($_SERVER['QUERY_STRING'] == 'albums') { $listDirectories = true; if(is_dir($path)) { $dir = opendir($path); while(false !== ($file = readdir($dir))) { $type = filetype($path ."/". $file); if($file != "." && $file != ".." && $file != "Thumbs.db" && $listDirectories && $type == "dir") { $list_dir[] = $file; } } } closedir($dir); foreach($list_dir as $subdir) { echo $subdir.'<br />'; if ($handle = opendir($path.$subdir)) { while (false !== ($files = readdir($handle))) { if ($files != "." && $files != "Thumbs.db" && $files != "..") { echo $files.'<br />'; } } echo '<br />'; closedir($handle); } } ?> this outputs: Band Event 1 gearsbg.jpg Band Event 2 brownsbg1.jpg halobg1.jpg which is correct. but for band event 2 i only want brownsbg1.jpg showing. help is appreciated. thanks in advance. - Mike [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 25, 2008 Share Posted November 25, 2008 Simply add a "break" within the last while loop: $path = 'photos/'; if($_SERVER['QUERY_STRING'] == 'albums') { $listDirectories = true; if(is_dir($path)) { $dir = opendir($path); while(false !== ($file = readdir($dir))) { $type = filetype($path ."/". $file); if($file != "." && $file != ".." && $file != "Thumbs.db" && $listDirectories && $type == "dir") { $list_dir[] = $file; } } } closedir($dir); foreach($list_dir as $subdir) { echo $subdir.'<br />'; if ($handle = opendir($path.$subdir)) { while (false !== ($files = readdir($handle))) { if ($files != "." && $files != "Thumbs.db" && $files != "..") { echo $files.'<br />'; break; } } echo '<br />'; closedir($handle); } } } Quote Link to comment Share on other sites More sharing options...
MikeDXUNL Posted November 25, 2008 Author Share Posted November 25, 2008 thanks a whole ton! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.