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); } } ?> Link to comment https://forums.phpfreaks.com/topic/61827-solved-php-directory-listing-script-question-please-help/ 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') ?> Link to comment https://forums.phpfreaks.com/topic/61827-solved-php-directory-listing-script-question-please-help/#findComment-307866 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. Link to comment https://forums.phpfreaks.com/topic/61827-solved-php-directory-listing-script-question-please-help/#findComment-307868 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); } } ?> Link to comment https://forums.phpfreaks.com/topic/61827-solved-php-directory-listing-script-question-please-help/#findComment-307871 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. Link to comment https://forums.phpfreaks.com/topic/61827-solved-php-directory-listing-script-question-please-help/#findComment-307875 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] Link to comment https://forums.phpfreaks.com/topic/61827-solved-php-directory-listing-script-question-please-help/#findComment-307877 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 Link to comment https://forums.phpfreaks.com/topic/61827-solved-php-directory-listing-script-question-please-help/#findComment-307878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.