Fix php file

Discussion in 'Programming' started by cavendano, Feb 19, 2008.

  1. #1
    I am having problems with this php file. It displays the contents of all directories on the same page rather than following a directory structure.
    PM me if you can fix this and the cost involved...thank you
    <?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>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"text-transform: uppercase\"><a href=\"?page=filter&location=$dirnames&section=$back_root\">$list_name[1]</font></a>&nbsp;&nbsp;&nbsp;</td>\n"; 
    }else{
    echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"text-transform: uppercase\"><a href=\"?page=filter&location=$dirnames&section=$back_root\">$dirnames</font></a>&nbsp;&nbsp;&nbsp;</td>\n"; 
    } 
    }
    for ($x=$i; $x<$columns ; $x++) 
    echo "<td></td>"; 
    echo "</tr></table>\n"; 
    ?>
    
    PHP:

     
    cavendano, Feb 19, 2008 IP
  2. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    What do you want it to do? Currently it works out all the subdirectories of the current directory, then for each of those subdirectories it outputs:
    - The subdir itself
    - Every parent dir of that subdir

    So for something like my/directory/structure it would output:
    my
    my
    directory
    my
    directory
    structure
     
    lephron, Feb 19, 2008 IP
  3. cavendano

    cavendano Well-Known Member

    Messages:
    360
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 1
    As Buyer:
    100% - 0
    #3
    what I wanted it to do is first list parent directorys
    - Every parent dir

    then when user selects directory..the sub directories appear

    so take for example /myprimary/mysecondary/file.filetype

    when it outputs the initial structure it would show
    my primary

    when I click it it would show
    my secondary

    when i click that it would show
    file.filetype

    your right as of now its just putting everything out on display when it initially loads...so even if I had categorized the folders it doesnt matter as they all get put out on the first page
     
    cavendano, Feb 19, 2008 IP