note 61297 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:01:40 +0000 |
| Subject: | note 61297 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126517@lists.php.net to get a copy of this message | ||
Note Submitter: Marijan Greguric
----
Example directory tree with javascript
<script>
function pokazi(dir){
alert(dir);
x=document.getElementById(dir);
if(x.style.display == "none"){
x.style.display = "";
}else{
x.style.display = "none";
}
}
</script>
</head>
<body>
<?php
$path= "../../upload/";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir("$path".$file)){
echo "<div style=\"padding-left: 2px; margin: 0px; border: 1px solid
#000000;\" >";
echo "|-<b><a href=\"#\"
onClick=pokazi(\"$file\")>$file</a></b><br />\n";
$id="$file";
dirT("$path$file/",$id);
}else{
echo "$file<br />\n";
}
}
}
echo "</div>";
closedir($handle);
}
function dirT($path,$id){
echo "<div style=\"padding-left: 2px; margin: 2px; border: 1px solid #000000;
display:none \" id=\"$id\">";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir("$path".$file)){
echo "<div style=\"padding-left: 10px; margin: 2px;
border: 1px solid #000000; \" >";
echo "|-<a href=\"#\"
onClick=pokazi(\"$file\")>$file</a><br />\n";
$id="$file";
dirT("$path$file/",$id);
}else{
echo " --$file<br />\n";
}
}
}
echo "</div>";
closedir($handle);
}
echo "</div>";
}
?>