krazytim Posted November 13, 2007 Share Posted November 13, 2007 This is the default code from my installation of wamp. I edited it slighly for the project I am doing, but the basic code is the same. <?php $list_ignore = array ('.','..','exemples','phpmyadmin','sqlitemanager'); $handle=opendir("."); $msg = $langues[$langue]['txt_no_projet']; while ($file = readdir($handle)) { if (is_dir($file) && !in_array($file,$list_ignore)) { $msg = ''; echo '<a class="ditem" href="'.$file.'"><img src="dossier.gif" alt="Folder Icon" title="Folder Icon" class="noBorderImg" /> '.$file.'</a><br /> '; } } closedir($handle); echo $msg; ?> When I go to "Localhost" on my computer, everything works fine with this code. But, when I upload the file into a folder I want to index on my server, it no longer puts the folders in alphabetical order. Does anyone know of a way to add to this code to make the indexer render the list in alphabetical order? I know it is possible, because I found some pre-made scripts that did it, but they were too complex with the options. All I want is for the code to echo out that specific code and put it all in order. Thanks in advanced. Sorry if this is a common question/request, I tried to search but I had no luck. Regards, -Tim Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 13, 2007 Share Posted November 13, 2007 Just put the results into an array, sort the array and then display the results from the array: <?php $list_ignore = array ('.','..','exemples','phpmyadmin','sqlitemanager'); $msg = $langues[$langue]['txt_no_projet']; $folders = array(); //Open the file system object for reading $handle=opendir("."); //Iterate through the file objects and put the folders into an array while ($file = readdir($handle)) { if (is_dir($file) && !in_array($file,$list_ignore)) { $folders[] = $file; } } //Close the file system object closedir($handle); //Sort the folder array sort($folders); //Iterate through the array and display the folders foreach ($folders as $folder) { $msg = ''; echo "<a class=\"ditem\" href=\"$file\">"; echo "<img src=\"dossier.gif\" alt=\"Folder Icon\" title=\"Folder Icon\" class=\"noBorderImg\" /> "; echo "$file</a><br />"; } echo $msg; ?> Quote Link to comment Share on other sites More sharing options...
krazytim Posted November 13, 2007 Author Share Posted November 13, 2007 hmm, that sounds logical in how it works, but the links/text of the folder names don't show up. It just renders the folder images linking to the current url. It seems like something is happening to the $file variable. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 13, 2007 Share Posted November 13, 2007 Try: <?php $list_ignore = array ('.','..','exemples','phpmyadmin','sqlitemanager'); $msg = $langues[$langue]['txt_no_projet']; $folders = array(); //Open the file system object for reading $handle=opendir("."); //Iterate through the file objects and put the folders into an array while ($file = readdir($handle)) { if (is_dir($file) && !in_array($file,$list_ignore)) { $folders[] = $file; } } //Close the file system object closedir($handle); //Sort the folder array sort($folders); //Iterate through the array and display the folders foreach ($folders as $file) {//note $file not $folder $msg = ''; echo "<a class=\"ditem\" href=\"$file\">"; echo "<img src=\"dossier.gif\" alt=\"Folder Icon\" title=\"Folder Icon\" class=\"noBorderImg\" /> "; echo "$file</a><br />"; } echo $msg; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 13, 2007 Share Posted November 13, 2007 Doh! I originally thought you were listing files and not folders when I started working that code. After I reread your post I realized that you were displaying folders and changed the name of the variables to be more appropriate - I forgot to change the variable name used in the echo statements. Personally I would change the foreach to use $folder instead of $file and change the variable in the echo statements. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 13, 2007 Share Posted November 13, 2007 I agree - I just made the easiest change Quote Link to comment Share on other sites More sharing options...
krazytim Posted November 13, 2007 Author Share Posted November 13, 2007 Thank you guys very much I altered the echo statements a bit, but it works perfectly now. If you are curious what this was for, you can see it here: http://timsilva.com/archive/ - Now it does everything I need/want it to do and it fits the main design of my website. Thanks again, these forums are definitely gunna be bookmarked -Tim 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.