cavendano Posted February 12, 2008 Share Posted February 12, 2008 I cant seem to find the problem... currently the script im running is supposed to display the main directories , and when you click it it should display the subdirectories. for example: main1,main2,main3,main4 on one page and the hierarchy should be main1=>sub1, sub2 main2=>sub3, sub4 but what it is doing is main1,sub1,sub2,main2,main3,main4 all one page pretty much whats happening is that its listing all the directories on the same page... here is the php file. if this cant be fixed if you can let me know of a better alternative I am open to any suggestions <?php $cdir = dirname(__FILE__); $DirectoriesToScan = array(realpath($cdir)); $DirectoriesScanned = array(); while (count($DirectoriesToScan) > 0) { foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) { if ($dir = @opendir($startingdir)) { while (($file = readdir($dir)) !== false) { if (($file != '.') && ($file != '..') && ($file != 'files')) { $RealPathName = realpath($startingdir.'/'.$file); if (is_dir($RealPathName)) { if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName, $DirectoriesToScan)) { $DirectoriesToScan[] = $RealPathName; $DirList[] = $RealPathName; } } } } closedir($dir); } $DirectoriesScanned[] = $startingdir; unset($DirectoriesToScan[$DirectoryKey]); } } $DirList = array_unique($DirList); sort($DirList); echo "<br><table align=center width=100%>\n"; $columns=3; $i = 0; foreach ($DirList as $dirname) { if ($i == $columns) { echo "</tr><tr>"; $i = 0; } elseif ($i == 0) { echo "<tr>"; } $i++; $dirnames = str_replace("$cdir/","",$dirname); $back_root = dirname(__FILE__) . '/..'; $back_root = str_replace("/..","",$back_root); $back_root = str_replace("$cdir/","",$back_root); $back_root = str_replace("$root/m/","",$back_root); $dirnames = str_replace(" ","_",$dirnames); $count = count($DirList); if (strpos($dirnames,"/")){ $list_name = explode("/",$dirnames); echo "<td> <span style=\"text-transform: uppercase\"><a href=\"?page=filter&location=$dirnames§ion=$back_root\">$list_name[1]</font></a> </td>\n"; }else{ echo "<td> <span style=\"text-transform: uppercase\"><a href=\"?page=filter&location=$dirnames§ion=$back_root\">$dirnames</font></a> </td>\n"; } } for ($x=$i; $x<$columns ; $x++) echo "<td></td>"; echo "</tr></table>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/90750-i-cant-find-the-problemdirectory-listing/ 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.