jQuery File Tree
Written by Cory S.N. LaViska on March 25th, 2008
A configurable, AJAX file browser plugin for jQuery.
Contents
- Overview
- Features
- Compatibility
- Demo
- Download
- Usage
- Connector Scripts
- Version History
- Licensing & Terms of Use
- Special Thanks
- Comments
Overview
jQuery File Tree is a configurable, AJAX file browser plugin for jQuery. You can create a customized, fully-interactive file tree with as little as one line of JavaScript code.
Currently, server-side connector scripts are available for PHP, ASP, ASP.NET, JSP, and Lasso. If you’re a developer, you can easily make your own connector to work with your language of choice.
Features
- Produces valid, semantic XHTML
- Fully customizable via CSS
- Ability to style icons based on file extension
- Uses AJAX to fetch file information on the fly
- Easy to configure and implement
- Includes connector scripts for PHP and ASP.NET (C#)
- Supports custom connector scripts for extended functionality
- Customizable expand/collapse event
- Customizable expand/collapse speeds
- Supports jQuery easing functions
- Single- and multi-folder views
- Configurable load message
Compatibility
jQuery File Tree requires jQuery 1.2.6 or above and has been tested to work in the following browsers:
- Internet Explorer 6 & 7
- Firefox 2 & 3
- Safari 3
- Chrome
- Opera 9
Demo
View a live demonstration of the file tree with various options.
Download
Current version: Version 1.01 (12 April 2008)
This plugin is provided to you as-is, at absolutely no cost. If you would like to support its development, feel free to contribute any amount you prefer via PayPal. As always, you are welcome to contribute code for bug fixes and feature enhancements as well. Either way, thanks for supporting our efforts!
Usage
Dependencies
jQuery File Tree requires jQuery 1.2 or above. For easing effects, you will need the jQuery Easing Plugin or another jQuery easing plugin of your choice.
Creating a File Tree
In it’s simplest form, you can create a file tree using the following code:
$('#container_id').fileTree({ root: '/some/folder/' }, function(file) {
alert(file);
});
});
where #container_id is the ID of an empty DIV element that exists on your page. The file tree will automatically load when your page loads.
Configuring the File Tree
Parameters are passed as an object to the fileTree() function. Valid options include:
| Parameter | Description | Default Value |
|---|---|---|
| root | root folder to display | / |
| script | location of the serverside AJAX file to use | jqueryFileTree.php |
| folderEvent | event to trigger expand/collapse | click |
| expandSpeed | Speed at which to expand branches (in milliseconds); use -1 for no animation | 500 |
| collapseSpeed | Speed at which to collapse branches (in milliseconds); use -1 for no animation | 500 |
| expandEasing | Easing function to use on expand | None |
| collapseEasing | Easing function to use on collapse | None |
| multiFolder | Whether or not to limit the browser to one subfolder at a time | true |
| loadMessage | Message to display while initial tree loads (can be HTML) | Loading... |
To create a file tree with multiple parameters, your code will look something like this:
$('#container_id').fileTree({
root: '/some/folder/',
script: 'jqueryFileTree.asp',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: false
}, function(file) {
alert(file);
});
});
Styling the File Tree
The file tree relies 100% on CSS for styling. To give your users an aesthetically pleasing experience, you should either use the included stylesheet for your file tree or create your own. Refer to jqueryFileTree.css to make any changes in the styles.
Handling Feedback
When a file is selected, jQuery File Tree passes the filename back as a string. The easiest way to capture and handle this is by using an anonymous function. If you want to pass the selected filename to a function you create called openFile(), your code will look like this:
// do something with file
}
$(document).ready( function() {
$('#container_id').fileTree({ [options] }, function(file) {
openFile(file);
});
});
Connector Scripts
jQuery File Tree comes with a handful of serverside connector scripts that are used to read the file system on your server and return data to the clientside script via AJAX. The default connector script is jqueryFileTree.php. You can use a connector script for another language by setting the script parameter to the location of the script you want to use (see Configuring the File Tree). Alternatively, you can build a custom connector script to extend the functionality of jQuery File Tree to better suit your needs (see Custom Connector Scripts).
Connector scripts for the following languages are included in the download:
- PHP by Cory S.N. LaViska
- ASP (VBS) by Chazzuka
- ASP.NET (C#) by Andrew Sweeny
- ColdFusion by Tjarko Rikkerink
- JSP by Joshua Gould
- Lasso by Marc Sabourdin
- Lasso by Jason Huck
- Perl by Oleg Burlaca
- Python/Django by Martin Skou
- Ruby by Erik Lax
If you would like to share a connector that you’ve written for another language, let us know! We’ll be happy to add it to the download for everyone to use!
The connector scripts provided with jQuery File Tree are only designed to read information from a specified root folder. Although this is typically harmless, there exists a potential for malicious individuals to be able to view your entire directory structure by spoofing the root parameter. It is highly recommended that you add some form of check to your connector script to verify the path being scanned is a path that you want to allow visitors to see.
Custom Connector Scripts
You can create a custom connector script to extend the functionality of the file tree. The easiest way to do this is probably by modifying one of the scripts supplied in the download. If you want to start from scratch, your script should accept one POST variable (dir) and output an unsorted list in the following format:
<li class="directory collapsed"><a href="#" rel="/this/folder/">Folder Name</a></li>
(additional folders here)
<li class="file ext_txt"><a href="#" rel="/this/folder/filename.txt">filename.txt</a></li>
(additional files here)
</ul>
Note that the corresponding file extension should be written as a class of the li element, prefixed with ext_. (The prefix is used to prevent invalid class names for file extensions that begin with non-alpha characters.)
Version History
1.01
- Updated to work with foreign characters in directory/file names (12 April 2008)
1.00
- Initial release (24 March 2008)
Licensing & Terms of Use
This plugin is dual-licensed under the GNU General Public License and the MIT License and is copyright 2008 A Beautiful Site, LLC.
Special Thanks
A special thanks goes out to FAMFAMFAM for their excellent Silk Icon Set.













Comments
— Floopie on Mar 26th, 2008
— Coskun on Mar 27th, 2008
— Demetrios Kyriakis on Mar 27th, 2008
— Cory S.N. LaViska on Mar 27th, 2008
— Ihsan on Mar 27th, 2008
— John on Mar 28th, 2008
— Cory S.N. LaViska on Mar 28th, 2008
— Levi Lewis on Mar 28th, 2008
— John on Mar 28th, 2008
— Cory S.N. LaViska on Mar 28th, 2008
— Kevin on Mar 28th, 2008
— bali web designer on Apr 1st, 2008
— Bramus! on Apr 1st, 2008
— Daniele Di Bernardo on Apr 1st, 2008
— decimus on Apr 1st, 2008
— mark on Apr 1st, 2008
— Daniele Di Bernardo on Apr 2nd, 2008
— pavlentij on Apr 4th, 2008
— Ignacio on Apr 11th, 2008
— Cory S.N. LaViska on Apr 12th, 2008
— Ignacio on Apr 14th, 2008
— Prakaash on Apr 18th, 2008
— Luis on Apr 19th, 2008
— Travis Phipps on Apr 21st, 2008
— Travis Phipps on Apr 22nd, 2008
— Cory S.N. LaViska on Apr 22nd, 2008
— kaspar on Apr 22nd, 2008
— Travis Phipps on Apr 23rd, 2008
— Sabrina on Apr 24th, 2008
— Demetrios Kyriakis on May 1st, 2008
— Demetrios Kyriakis on May 1st, 2008
— adarsh on May 3rd, 2008
— Stephen on May 7th, 2008
— Ernest on May 7th, 2008
— Stephen on May 9th, 2008
— Stephen on May 9th, 2008
— Matt on May 10th, 2008
— Soulhuntre on May 14th, 2008
— Mato on May 23rd, 2008
— Seth on May 29th, 2008
— Dalibor on Jun 4th, 2008
— Rp on Jun 4th, 2008
— kpo on Jun 4th, 2008
— sam on Jun 12th, 2008
— Demetrios Kyriakis on Jun 15th, 2008
— Rp on Jun 16th, 2008
— Vincent on Jun 18th, 2008
— Rp on Jun 20th, 2008
— Chris on Jun 25th, 2008
— Deniz on Jun 26th, 2008
— matt on Jul 7th, 2008
— Allan on Jul 8th, 2008
— Richard van Zon on Jul 9th, 2008
— Richard van Zon on Jul 9th, 2008
— Allan on Jul 13th, 2008
— Allan on Jul 13th, 2008
— mogio on Jul 16th, 2008
— klima on Jul 17th, 2008
— Cherry on Jul 20th, 2008
— Felix on Jul 21st, 2008
— eugeny on Jul 22nd, 2008
— Nick on Jul 30th, 2008
— John on Jul 31st, 2008
— gab on Jul 31st, 2008
— user on Aug 2nd, 2008
— Eugeny on Aug 4th, 2008
— Cory S.N. LaViska on Aug 4th, 2008
— tiffany on Aug 6th, 2008
— Cory S.N. LaViska on Aug 6th, 2008
— Cory S.N. LaViska on Aug 6th, 2008
— tiffany on Aug 7th, 2008
— Ju on Aug 12th, 2008
— thomas on Aug 18th, 2008
— Ross on Aug 19th, 2008
— Berkowitz on Aug 21st, 2008
— kbrothers on Aug 24th, 2008
— Paul Jauregui on Aug 24th, 2008
— Rav on Aug 25th, 2008
— AddictDownload.com on Aug 26th, 2008
— Mike on Aug 27th, 2008
— Mike on Aug 27th, 2008
— Alex on Aug 28th, 2008
— Roland on Aug 28th, 2008
— Cory S.N. LaViska on Aug 29th, 2008
— yellow1912 on Sep 2nd, 2008
— Kim on Sep 3rd, 2008
— Devin on Sep 3rd, 2008
— Cory S.N. LaViska on Sep 3rd, 2008
— Andreas on Sep 5th, 2008
— Alex Torrance on Sep 8th, 2008
— Colin on Sep 11th, 2008
— Cory S.N. LaViska on Sep 14th, 2008
— Valery Buchinsky on Sep 24th, 2008
— dave on Sep 25th, 2008
— p0s3r on Sep 25th, 2008
— Ratheesh on Sep 26th, 2008
— tumaji on Sep 28th, 2008
— tce on Oct 7th, 2008
— Mike on Oct 16th, 2008
— Diptirmaya Rout on Oct 16th, 2008
— Cory S.N. LaViska on Oct 16th, 2008
— Paul Harvey on Oct 16th, 2008
— Manu on Oct 20th, 2008
— anunay on Oct 21st, 2008
— Stephen on Oct 21st, 2008
— Darin on Oct 24th, 2008
— Cory S.N. LaViska on Oct 26th, 2008
— Luke on Oct 30th, 2008
— Stephen on Nov 3rd, 2008
— Santhos Webdesign on Nov 3rd, 2008
— adeel on Nov 3rd, 2008
— Cory S.N. LaViska on Nov 3rd, 2008
— Jolle on Nov 5th, 2008
— LRancez on Nov 6th, 2008
— LRancez on Nov 6th, 2008
— LRancez on Nov 6th, 2008
— Sean on Nov 6th, 2008
— co. on Nov 7th, 2008
— Nick Levett on Nov 7th, 2008
— LRancez on Nov 7th, 2008
— co. on Nov 7th, 2008
— LRancez on Nov 10th, 2008
— KlerMor on Nov 11th, 2008
— Angelo Moreira on Nov 12th, 2008
— Cory S.N. LaViska on Nov 12th, 2008
— Sean on Nov 12th, 2008
— KlerMor on Nov 13th, 2008
— serialbob on Nov 13th, 2008
— Sven on Nov 17th, 2008
— shiva on Nov 18th, 2008
— olly on Nov 18th, 2008
— ALexa on Nov 19th, 2008
— dr.emi on Nov 21st, 2008
— Tyler on Nov 21st, 2008
— Tyler on Nov 21st, 2008
— Tyler on Nov 24th, 2008
— demianus on Nov 25th, 2008
— demianus on Nov 25th, 2008
— Vincent LePes on Nov 26th, 2008
— Cory S.N. LaViska on Nov 27th, 2008
— miba on Nov 29th, 2008
— Daniel on Nov 30th, 2008
— Biagio on Dec 2nd, 2008
— Shahriat on Dec 3rd, 2008
— amir on Dec 3rd, 2008
— ekid on Dec 6th, 2008
— bara on Dec 9th, 2008
— Marco Mocellini on Dec 11th, 2008
— Tyler on Dec 11th, 2008
— Simon on Dec 18th, 2008
— Marco on Dec 20th, 2008
— Marco on Dec 20th, 2008
— Douson on Dec 24th, 2008
— Janm on Dec 28th, 2008
— Stefan on Jan 3rd, 2009
— Jason on Jan 7th, 2009
— Sergio on Jan 15th, 2009
— jon on Jan 16th, 2009
— Tyler on Jan 16th, 2009
— devrim on Jan 19th, 2009
— devrim on Jan 19th, 2009
— Mike on Jan 21st, 2009
— NetOperator Wibby on Jan 22nd, 2009
— Albert on Jan 23rd, 2009
— R on Jan 23rd, 2009
— Brett Slaski on Jan 23rd, 2009
— Abs on Jan 27th, 2009
— Nathaniel on Feb 1st, 2009
— denisK on Feb 2nd, 2009
— Bill on Feb 2nd, 2009
— Carlos on Feb 5th, 2009
— Carlos on Feb 5th, 2009
— Q5 Webdesign on Feb 5th, 2009
— Kenia on Feb 5th, 2009
— Nathan Brown on Feb 6th, 2009
— Nathan Brown on Feb 6th, 2009
— usman on Feb 11th, 2009
— John on Feb 11th, 2009
— Tyler on Feb 12th, 2009
— Abs on Feb 12th, 2009
— Jason on Feb 12th, 2009
— mahmoud on Feb 15th, 2009
— -=Dan=- on Feb 15th, 2009
— Gattis on Feb 24th, 2009
— Brandon on Feb 24th, 2009
— Alejandro Barrere on Mar 1st, 2009
— Alejandro Barrere on Mar 1st, 2009
— Carl on Mar 5th, 2009
— sam on Mar 5th, 2009
— sam on Mar 5th, 2009
— Kaz on Mar 8th, 2009
— Roberto on Mar 11th, 2009
— mofazzal on Mar 12th, 2009
— Roberto on Mar 13th, 2009
— sivas on Mar 15th, 2009
— Abs on Mar 15th, 2009
— Anne on Mar 15th, 2009
— Anne on Mar 15th, 2009
— Abs on Mar 16th, 2009
— c0d3r on Mar 16th, 2009
— Giovanni on Mar 21st, 2009
— artico on Mar 23rd, 2009
— Subhashini on Mar 25th, 2009
— Raghuram on Apr 1st, 2009
— jamie on Apr 1st, 2009
— Ciaran on Apr 2nd, 2009
— Cory S.N. LaViska on Apr 2nd, 2009
— Ciaran on Apr 2nd, 2009
— Virgulino on Apr 2nd, 2009
— Raghuram Reddy on Apr 3rd, 2009
— Virgulino on Apr 3rd, 2009
— Raghuram Reddy on Apr 6th, 2009
— Pradeep on Apr 8th, 2009
— Virgulino on Apr 8th, 2009
— Jason on Apr 10th, 2009
— vito on Apr 14th, 2009
— Ramiro on Apr 14th, 2009
— vito on Apr 14th, 2009
— Ruud on Apr 16th, 2009
— Ruud on Apr 16th, 2009
— Christopher Werby on Apr 21st, 2009
— Ruben Restrepo on Apr 22nd, 2009
— Martin Revert on Apr 23rd, 2009
— Utopia on Apr 23rd, 2009
— Kujo on Apr 23rd, 2009
— Adam on Apr 25th, 2009
— Adam on Apr 25th, 2009
— Webagentur on Apr 29th, 2009
— darius on Apr 30th, 2009
— Rich on May 3rd, 2009
— Arun on May 4th, 2009
— sudheer on May 4th, 2009
— renobird on May 6th, 2009
— Fernando on May 9th, 2009
— Susanta Samanta on May 12th, 2009
— Sam on May 13th, 2009
— Girish on May 13th, 2009
— fruitbatinshades on May 15th, 2009
— fruitbatinshades on May 15th, 2009
— Mansour on May 19th, 2009
— Mansour on May 19th, 2009
— Steve on May 19th, 2009
— Gregg on May 19th, 2009
— khalil Majdalawi on May 20th, 2009
— gabe on May 22nd, 2009
— fruitbatinshades on May 28th, 2009
— Girish on May 29th, 2009
— engine on May 31st, 2009
— Stef on May 31st, 2009
— Vertigo on Jun 3rd, 2009
— Vertigo on Jun 3rd, 2009
— Bzouchir on Jun 3rd, 2009
— Cory S.N. LaViska on Jun 3rd, 2009
— mikaweb on Jun 4th, 2009
— Stef on Jun 5th, 2009
— vijay joshi on Jun 6th, 2009
— Sinan Yasar on Jun 8th, 2009
— Umair Aslam on Jun 8th, 2009
— Steven Culshaw on Jun 9th, 2009
— Sinan Yasar on Jun 9th, 2009
— Alex H on Jun 10th, 2009
— Paul on Jun 11th, 2009
— Cory S.N. LaViska on Jun 11th, 2009
— Umair Aslam on Jun 11th, 2009
— applet on Jun 15th, 2009
— Girish on Jun 19th, 2009
— Ben on Jun 21st, 2009
— Alan on Jun 23rd, 2009
— Girish on Jun 25th, 2009
— aaloy on Jun 25th, 2009
— levin on Jun 26th, 2009
— Carl on Jun 26th, 2009
— Rick Gladwin on Jul 1st, 2009