cmbcorp Posted July 26, 2007 Share Posted July 26, 2007 Hi, I have a directory listing php script on my server and i only want to display the directorys in the list and not the files with extensions. can anyone assist me with this? i would really appreciate your help. Cheers, *** my code is as follows:*** <?php $dir = './'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh))!== false) { if($file <> '.' && $file <> '..') echo '<a href="'.$file.'">'.$file.'</a><br />'; } closedir($dh); } } ?> Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted July 26, 2007 Share Posted July 26, 2007 add this condition <?php if(filetype($file)=='dir') ?> Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted July 26, 2007 Author Share Posted July 26, 2007 i just added that to the code and it didnt display any files in the dir. any ideas? thanks for your help once again. Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted July 26, 2007 Share Posted July 26, 2007 i didnt test this, please try <?php $dir = './'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh))!== false) { if(filetype($file)=='dir') echo '<a href="'.$file.'">'.$file.'</a><br />'; } closedir($dh); } } ?> Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted July 26, 2007 Author Share Posted July 26, 2007 i didnt test this, please try <?php $dir = './'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh))!== false) { if(filetype($file)=='dir') echo '<a href="'.$file.'">'.$file.'</a><br />'; } closedir($dh); } } ?> mate.. thanks. that works great... one thing though it displays the dirs like this: ..[/url] NandosBendigo[/url] .[/url] NandosLysterfield[/url] NandosShepparton[/url] anyway to get the list downwords and not side ways? cheers. thanks for your help. Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted July 26, 2007 Share Posted July 26, 2007 remove this -> '[/url]' echo '<a href="'.$file.'">'.$file.'[/url] Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted July 26, 2007 Author Share Posted July 26, 2007 remove this -> '[/url]' echo '<a href="'.$file.'">'.$file.'[/url] sorry i modified my comment. can i list the directory contents in a list and not on the same line? cheers 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.