Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post Spaces to display levels in dir structure list ?

    Good day to you all,

    working on listing a directory the way I want, I'm trying that for each level of file there is a number of spaces in front of the file and/or folder of that level. EX :

    Folder 1
    --Folder 2
    --Image 1
    --Image 2
    --Image 3
    Image 1
    Image 2

    How can I add that spacing on each level ?

    Here is my code :


    Code:
    
    <?php
    
    $directory = "Art/";
    function dirList ($directory)
    {
    
        //create 2 arrays - one for folders and one for files
       $folders = array();
       $files = array();
    
        // create a handler for the directory
        $handler = opendir($directory);
    
        // keep going until all files in directory have been read
    while (false !== ($file = readdir($handler))) {  
    
            // if $file isn't this directory or its parent,
            // add it to the results array
            if ($file != '.' && $file != '..')
            
            // If file is directory, mark it in bold.
           if(is_dir($directory.$file)) { 
            array_push($folders,$file);
            
            // Else not styled
            }else{
            array_push($files,$file);
            
        }
        }
    
    
        // tidy up: close the handler
        closedir($handler);
    
        foreach($folders as $folder) {
          echo "<strong>".$folder."</strong>  <a href=\"javascript:show('".$folder."');\">Show</a>- <a href=\"javascript:hide('".$folder."');\">Hide</a><br />";
    		
    echo "<div id=\"".$folder."\">";
    dirList($directory.$folder.'/');
    
    echo "<br/><br/></div>";
    	
    	
        }
    
        foreach($files as $file) {
          echo $file."<br />";
        }
        
    
    }
    
    dirList($directory);
    
    ?>

    Thanks !

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    as you said in the title, "dir structure list" use a list, ul/li and span and you can go how deeper you want.
    something like that:
    Code:
    <ul>
      <li>
          <span>folder name</span>
          <ul>
              <li>first file info</li>
              ....
              <li>
                  <span>inner folder name</span>
                  <ul>
                     .....
                  </ul>
              </li>
              ...
              <li>last file info</li>
           </ul>
       </li>
    </ul>
    then style it with css to look how you like.

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •