作者:lock2502898047_947 | 来源:互联网 | 2013-08-15 09:24
text = $text;
$this->children = $children;
}
}
class Commonfile{
var $text = "";
var $leaf = true;
public function __construct($text, $leaf){
$this->text = $text;
$this->leaf = $leaf;
}
}
function listFiles($dir)
{
$handle=opendir($dir); //打开目录
$array = array();
readdir($handle); //去掉.和..这两个特殊表示
readdir($handle);
$file=readdir($handle);
if(!$file){
// array_push($array, new DirectoryClass($file, "")); //空文件目录,它的值是空值
}else{
do {
if(is_dir("$dir/$file")) //所得到的文件名是否是一个目录
{
array_push($array, new DirectoryClass($file, listFiles("$dir/$file")) );
} else {
array_push($array, new Commonfile($file, true));
}
}while($file=readdir($handle));
}
return $array;
}
$dir="C:/Apache2.2/htdocs/superadmin/tree/test";
//print_r(listFiles($dir));
echo "
";
echo json_encode(listFiles($dir));
?>
最后得到的数据是:
[{"text":"jquery.treeview.css","leaf":true},{"text":"lala","children":[]},{"text":"lib","children":
[{"text":"jquery.COOKIE.js","leaf":true},{"text":"jquery.js","leaf":true},{"text":"jquery.treeview.async.js","leaf":true},
{"text":"jquery.treeview.js","leaf":true}]},{"text":"source.php","leaf":true},{"text":"tree2.html","leaf":true}]