Jump to content

i cant find the problem...directory listing


cavendano

Recommended Posts

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&section=$back_root\">$list_name[1]</font></a>   </td>\n"; 
}else{
echo "<td>    <span style=\"text-transform: uppercase\"><a href=\"?page=filter&location=$dirnames&section=$back_root\">$dirnames</font></a>   </td>\n"; 
}  
}
for ($x=$i; $x<$columns ; $x++) 
echo "<td></td>"; 
echo "</tr></table>\n"; 
?> 

 

Link to comment
https://forums.phpfreaks.com/topic/90750-i-cant-find-the-problemdirectory-listing/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.