PHP displays the file in which the current file resides and all the files in the folder as a tree

  • 2020-03-30 00:52:09
  • OfStack

 
<div id="jQ-menu"> 
<?php 
$path = "./"; 
function createDir($path = '.') 
{ 
if ($handle = opendir($path)) 
{ 
echo "<ul>"; 
while (false !== ($file = readdir($handle))) 
{ 
if (is_dir($path.$file) && $file != '.' && $file !='..') 
printSubDir($file, $path, $queue); 
else if ($file != '.' && $file !='..') 
$queue[] = $file; 
} 
printQueue($queue, $path); 
echo "</ul>"; 
} 
} 
function printQueue($queue, $path) 
{ 
foreach ($queue as $file) 
{ 
printFile($file, $path); 
} 
} 
function printFile($file, $path) 
{ 
echo "<li><a href="".$path.$file."">$file</a></li>"; 
} 
function printSubDir($dir, $path) 
{ 
echo "<li><span class="toggle">$dir</span>"; 
createDir($path.$dir."/"); 
echo "</li>"; 
} 
createDir($path); 
?> 
</div> 

Related articles: