/*
제작자이름 : navyism
제작자메일 : navyism@chol.com
관련사이트 : http://navyism.com
디렉토리 트리구조를 탐색기형태로 가져오기
*/
<?
$start = "./"; //시작위치
$limit = 50; //폴더당 최대서브폴더
function get_tree($start,$depth=0,$root=0)
{
global $limit;
for($i=0;$i<$depth;$i++)
{
$block.="<img src=blank.gif align=absmiddle border=0>";
}
unset($buff);
if($depth)
{
$position="absolute";
$visibility="hidden";
}
else
{
$position="";
$visibility="visible";
}
while($dir=@readdir($dh))
{
if($dir=="." || $dir=="..")
{
continue;
}
if(!$dh2=@opendir("$start/$dir"))
{
continue;
}
$buff[]=$dir;
@closedir($dh2);
}
@sort($buff);
if($i>=$limit)
{
$buff[$i]="more.....";
}
for($i=0;$i<sizeof($buff);$i++)
{
echo "<div open=0
style='height:17;position:$position;visibility:$visibility'
id='tree_${root}_${i}'>".$block." <a onfocus=this.blur()
href=\"javascript:show_div('${root}_${i}')\"><img
name='button_${root}_${i}' src=button+.gif align=absmiddle border=0></a> <img
name='folder_${root}_${i}' src=folder_close.gif align=absmiddle border=0> <input
type=checkbox name='chk_${root}_${i}' onclick=flagging('${root}_${i}',this.checked)> <a onfocus=this.blur()
href=\"javascript:show_div('${root}_${i}')\"><font id='font_${root}_${i}' howmany=0>$buff[$i]</font></a><span id='span_${root}_${i}'></span></div>\n";
if($i>=$limit)
{
break;
}
get_tree("$start/$buff[$i]",$depth+1,$root."_".$i);
}
@closedir($dh);
}
?>
<html>
<body>
<style>
A:link {
color:#000000;
text-decoration: none;
}
A:visited {
color:#000000;
text-decoration: none;
}
A:active {
color:#000000;
text-decoration: none;
}
A:hover {
color:#0000cc;
text-decoration: underline;
}
body
{
font-size:9pt;
font-family:tahoma,굴림;
line-height:145%;
}
</style>
<script language=javascript>
function ereg(exp,str)
{
exp=new RegExp(exp);
exp=str.match(exp);
return exp;
}
function flagging(id,chk)
{
this_chk=id.split("_");
temp_chk="0";
for(var i=1;i<this_chk.length;i++)
{
temp_chk+="_"+this_chk[i];
span_chk=eval("span_"+temp_chk);
font_chk=eval("font_"+temp_chk);
if(chk)
{
font_chk.howmany++;
}
else
{
font_chk.howmany--;
}
if(font_chk.howmany)
{
font_chk.style.color="#0000cc";
span_chk.innerHTML="<img src=flag.gif align=absmiddle>";
}
else
{
font_chk.style.color="#000000";
span_chk.innerHTML="";
}
}
}
function show_div(id)
{
this_div=eval("tree_"+id);
this_btn=eval("document.button_"+id);
this_fld=eval("document.folder_"+id);
this_haveson=0;
if(this_div.open==0)
{
this_div.open=1;
for(var i=0;i<<?=$limit?>;i++)
{
try
{
chld_div=eval("tree_"+id+"_"+i);
chld_div.style.position='';
chld_div.style.visibility='visible';
this_haveson=1;
}
catch(Exception)
{
break;
}
}
if(this_haveson)
{
this_btn.src='button-.gif';
this_fld.src='folder_open.gif';
}
else
{
this_btn.src='blank.gif';
this_fld.src='folder_close.gif';
}
}
else
{
close_all(id);
}
}
function close_all(id)
{
this_div=eval("tree_"+id);
this_div.open=0;
this_btn=eval("document.button_"+id);
if(!ereg("blank\.gif$",this_btn.src))
{
this_btn.src='button+.gif';
}
this_fld=eval("document.folder_"+id);
this_fld.src='folder_close.gif';
for(var i=0;i<<?=$limit?>;i++)
{
try
{
chld_div=eval("tree_"+id+"_"+i);
is_ok=1;
}
catch(Exception)
{
is_ok=0;
}
if(!is_ok)
{
break;
}
else
{
chld_div.style.position='absolute';
chld_div.style.visibility='hidden';
chld_btn=eval("document.button_"+id+"_"+i);
if(!ereg("blank\.gif$",chld_btn.src))
{
chld_btn.src='button+.gif';
}
chld_fld=eval("document.folder_"+id+"_"+i);
chld_fld.src='folder_close.gif';
close_all(id+"_"+i);
}
}
}
</script>
<form name=reg>
<?
get_tree($start);
?>
</form>
<span id=res></span>
</body>
</html>
미리보기
http://libphp.com/explorer
이미지파일 (압축을 풀어서 소스와 같은 폴더에 위치시키세요)
출처
http://libphp.com/