bostonjim Posted June 16, 2010 Share Posted June 16, 2010 The following code is working for me, but the displayed results are not in alphabetical order. I understand that I need to put them in an array and sort them, but don't have the foggiest about how to do that. <?php function DirDisply($data) { $TrackDir=opendir("."); while ($file = readdir($TrackDir)) { if ($file == "." || $file == "..") { } else { print "<tr><td><font face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=$file target=_blank>$file</a></font> </td>"; } } closedir($TrackDir); return $data; } ?> <b><font face="Verdana, Arial, Helvetica, sans-serif">Current Directory Contain Following files and Sub Directories...</font></b> <p> <? @ DirDisply($data); ?> Link to comment https://forums.phpfreaks.com/topic/204921-noobie-question-alphabetizing-folder-contents-list/ Share on other sites More sharing options...
kenrbnsn Posted June 16, 2010 Share Posted June 16, 2010 Use the glob function instead: <?php $tmp = glob('.*'); echo '<pre>' . print_r($tmp,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/204921-noobie-question-alphabetizing-folder-contents-list/#findComment-1072816 Share on other sites More sharing options...
bostonjim Posted June 16, 2010 Author Share Posted June 16, 2010 I'm a little embarrassed to say I don't know how to integrate that into the code... Link to comment https://forums.phpfreaks.com/topic/204921-noobie-question-alphabetizing-folder-contents-list/#findComment-1072820 Share on other sites More sharing options...
bostonjim Posted June 16, 2010 Author Share Posted June 16, 2010 I tried using that and this is how the result appears: Array ( [0] => . [1] => .. ) So I must need to add it into the code I posted originally and not use it by itself, since it isn't grabbing any of the files or directories. Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/204921-noobie-question-alphabetizing-folder-contents-list/#findComment-1072837 Share on other sites More sharing options...
bostonjim Posted June 16, 2010 Author Share Posted June 16, 2010 NEVERMIND. I see that the * was a wildcard and after removing the preceding "." (which was probably put there for an example) everything shows up. Thanks! Link to comment https://forums.phpfreaks.com/topic/204921-noobie-question-alphabetizing-folder-contents-list/#findComment-1072838 Share on other sites More sharing options...
bostonjim Posted June 16, 2010 Author Share Posted June 16, 2010 I have a slightly different question but it should be easy for the pros. When I use this everything is showing up: <?php $tmp = glob('*'); echo '<pre>' . print_r($tmp,true) . '</pre>'; ?> But it appears like this on the screen: Array ( [0] => archive.php [1] => comments.php [2] => directorycontents.php [3] => footer.php [4] => functions.php [5] => header.php [6] => images [7] => index.php [8] => page.php ) How can I make it not show the part which says "Array" and the parenthesis. And how can I make these into links? I did my best to add the href tags into the echo line but I can't make it work. Link to comment https://forums.phpfreaks.com/topic/204921-noobie-question-alphabetizing-folder-contents-list/#findComment-1072839 Share on other sites More sharing options...
bostonjim Posted June 16, 2010 Author Share Posted June 16, 2010 Got it working, thanks. Link to comment https://forums.phpfreaks.com/topic/204921-noobie-question-alphabetizing-folder-contents-list/#findComment-1072843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.