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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.