Download folder tree


Bookmark and Share

Download files



This script is licensed under LGPL. Commercial licenses are also available


This script requires that you have PHP support. I'm planning to implement support for other server side languages later on. If you like the script and wants to convert the code to JSP, ASP or similar, please do so. If you send me the new script(, I will post the script on this website

Setup information

The tree is a PHP class. The first you have to do is to include the class file:
Then you create a object of the class like this:
$tree = new dhtmlgoodies_tree();

The next step is to add nodes to the tree. There are two methods to choose from in order to do this. The new method(added 2011) addToArrayAss accepts an array as only argument.

  'id' => 1,
  'title' => "America",
  'parentId' => 0,
  'url' => "",
  'target' => "_blank",
  'icon' => "images/dhtmlgoodies_sheet.gif",
  'onclick' => "alert('hello')"

parentId, url, target, icon and onclick are optional parameters.

You can also add nodes with the addToArray() method. This method takes up to 7 arguments(ID, title, parent ID, url, target and icon). The last arguments(icon) and onclick are optional.

  "images/dhtmlgoodies_sheet.gif","alert('id is 8')");

The 'ID' identifies the node in the tree, thus it have to be unique. Title is the title of the node in the tree while parent ID is used for child nodes to identify it's parent. Url and target are optional arguments. The target is typically used if you're dealing with a frameset and wants the url to be opened in another frame than where the tree is.

You can see in the example code above, that "USA" have ID=2 and parentID=1. "1" is a the unique identification of USA in the tree and the parentID refers to the parent node which is "America".

Root nodes doesn't have any parent ID(example: America)

Usually, you don't add these nodes manually as I have done here. The best approach is to get them from a database. Example:
$res = mysql_query("select ID,title,parentID,url from table_category") or die(mysql_error());
while($inf = mysql_fetch_array($res)){
    'id' => $inf["ID"],
    'title' = >$inf["title"],
    'parentId' => $inf["parentID"],
    'url' => $inf["url"],
    'target' => "_blank")

When all the nodes has been added, you have to call the functions which outputs Javascript, CSS and the HTML to the browser:

For more info see the example file(dhtmlgoodies_tree.html) in the downloadable zip file and open the file dhtmlgoodies_tree_index.html to see how it works in your browser.

Expand all/Collapse all

You have two javascript functions which you could use to expand or collapse all nodes. The name of these functions are:

  • expandAll()
  • collapseAll()


No one has commented this - be first!

Post your comment

Don't have an avatar? Create one at

Confirmation code:

Go to

About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2024