Topic: Folder Tree

I think that's what it's called wink
Anyways, I want a script that will display the contents of a given folder (including all subfolders) with the ability to click on something to expand/contract the folders. The problem is, I have a rather specific need that I can't find a script to satisfy. So, I wanted to see if anyone here had any suggestions. smile
I need a majority of it to be able to be auto-generated by a PHP script, (not a DB, which it seems is a popular thing to offer: I want it to read the dir, and generate the files/subfolders/files and folders in subfolders/etc). I've had no luck in modifying several, so I'm hoping you guys know of one that I wouldn't have to heavily mod (ideally, I have to do next to nothing) to do this with tongue

Re: Folder Tree

well you can use something like this http://www.treeview.net/treemenu/demos.asp but you need a script to create the folder structure in php

or you could reload the page on every click...

Re: Folder Tree

I have an old version of the Treeview one and a script that works with it: the tree is always expanded in Firefox.
But when I upgraded to the new one, I was unable to figure out how to get my script to work with it tongue

Re: Folder Tree

Anybody?

5

Re: Folder Tree

Look at >> http://www.sortons.net/photos/test2.htm

Advantages are
- very light JS code
- 100% degradable (old browsers see simply the list)
- no limit of tree !!!

Happy ? smile

6 (edited by Smartys 2005-03-14 11:41)

Re: Folder Tree

Mmm, looks good smile
So where can I get it? tongue

7

Re: Folder Tree

Rod wrote:

Look at >> http://www.sortons.net/photos/test2.htm

Advantages are
- very light JS code
- 100% degradable (old browsers see simply the list)
- no limit of tree !!!

Happy ? smile

<li class="tree"><img class="tree" src="images/page.gif" alt="album" />

These stuff are repeating all over the place in the script. It would be a good idea to remove the class="tree" from the <li> because you can access them through ul.tree li {} anyway.

The same thing with <img> as well. It could be done by using only CSS and assigned to ul.tree li {} or ul.tree li a {}.

Just some suggestion. Btw, nice tree view script. wink

8 (edited by Nibbler(cpg) 2005-03-14 16:39)

Re: Folder Tree

<script type="text/javascript" language="javascript">
function togVis(id) {
    var list = id+"List";
    list = document.getElementById(list);
    var button = id+"Button";
    button = document.getElementById(button);
    if(list.style.display == "block") {
        list.style.display = "none";
        button.src = "images/nolines_plus.gif";
    } else {
        list.style.display = "block";
        button.src = "images/nolines_minus.gif";
    }
}
</script>
<style type="text/css">
img {border: 0; vertical-align: middle}
li {list-style: none outside}
ul {display: none; padding-left: 20; padding-top: 0; margin: 0}
body {font-family : Verdana, Arial, Helvetica, sans-serif; font-size: 12px}
</style>
<?

$tree = dir_parse('admin');
maketree($tree);

function dir_parse($path)
{
    if ($dir = opendir($path))
    {
        $thisdir = array();
        while (false !== ($file = readdir($dir)))
        {
            if  ($file != '.' && $file != '..')
            {
                if (is_dir("$path/$file"))
                {
                    $thisdir[$file] = dir_parse("$path/$file");
                } else {
                    $thisdir[] = $file;
                }
            }
        }
        asort($thisdir, SORT_STRING);
        return $thisdir;
    }
}

function maketree($tree)
{
    static $i = 0;
    
    foreach ($tree as $path=>$file){
        if (is_array($file)){
            echo "<li><a href=\"#\" onclick=\"togVis('$i'); return false;\"><img src=\"images/nolines_plus.gif\" alt=\"+\" id=\"{$i}Button\" /></a>$path";
            echo "<ul id=\"{$i}List\">";
            $i++;
            maketree($file);
            echo "</ul></li>";
        } else {
            echo "<li><img src=\"images/page.gif\" alt=\"$file\" />$file</li>";
        }
    }
}
?>

That should make a tree from a directory listing smile

Re: Folder Tree

Nibbler, you pwn: that's EXACTLY what I need big_smile