TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Spaces to display levels in dir structure list ? (http://www.talkphp.com/general/4132-spaces-display-levels-dir-structure-list.html)

Peuplarchie 04-13-2009 04:19 PM

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 :


PHP 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 !

ETbyrne 04-13-2009 04:32 PM

Make it so that it generates the HTML so it looks something like this:

Code:

<ul>
  <li>file</li>
  <li>dir<ul>
    <li>file</li>
    <li>file</li>
  </ul></li>
  <li>file</li>
  <li>file</li>
</ul>

It's really more of a HTML/CSS issue than a PHP one

Salathe 04-13-2009 05:40 PM

Separate your concerns.
  1. Fetch a hierarchical list of files/folders.
  2. Display that list however you want.

You seem to have many posts/threads asking pretty much the same thing, yet always revert back to the same basic code. Are you listening and taking note of replies to your threads?

Peuplarchie 04-13-2009 05:53 PM

I'm learning with many examples and trying to see the different way of coding.

I'm it could look as such, i'm soo a bit too.


All times are GMT. The time now is 03:29 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0