For those using the Treeview plugin: PHP directory builder
Drop me a thanks if you find it any good and you'll make me happy!
$dir_id = if of the whole structure (the one you'll call in you jQuery)
$dir_class...
$path is the path to scan
$extension is a filter. I used it to find all my PHP files for instance
$file_on_click_event. I give you 1 guess
- function BuildFileList($dir_id, $dir_class = "filetree", $path="", $extension="", $file_on_click_event=""){
- if(empty($path))$path = $_SERVER['DOCUMENT_ROOT'];
- function _BuildFileList($path, $extension, $file_on_click_event=""){
- /*******************************************************************************
- *
- * Sets events and a bit of initialision
- *
- ******************************************************************************/
- $list = "";
- $dir_handle = @opendir($path) or die("Unable to open $path");
- while (false !== ($file = readdir($dir_handle))) {
- /*******************************************************************************
- *
- * It's a directory! Mainly adds the folder header and does a recursion
- *
- * **** WILL NOT INCLUDE SVN directories ****
- *
- ******************************************************************************/
- if(is_dir("$path/$file")){
- if(".."!=$file&&"."!=$file&&".svn"!=$file){
- $list .= "<li class='closed'>".
- "<span class='folder'>$file</span>".
- _BuildFileList("$path/$file", $extension, $file_on_click_event).
- "</li>";
- }
- }else{
- /*******************************************************************************
- *
- * It's a file. Appends
- *
- ******************************************************************************/
- if(empty($extension)){
- $list .= "<li><span class='file' onclick='$file_on_click_event' style='cursor:pointer;'>$file</span></li>\n";
- }else{
- $path_parts = pathinfo("$path/$file");
- if(isset($path_parts["extension"])){
- if($extension==$path_parts["extension"]){
- $list .= "<li><span class='file' onclick='$file_on_click_event' style='cursor:pointer;'>$file</span></li>\n";
- }
- }
- }
- }
- }
- closedir($dir_handle);
- return "<ul>$list</ul>";
- }
- $content = _BuildFileList($path, $extension, $file_on_click_event);
- return "<ul id='$dir_id' class='$dir_class'><li>$content</li></ul>";
- }