如何使递归成为我的索引文件管理器



我正在用php制作一个文件资源管理器,但我必须将文件放在每个文件夹中,才能用我的索引访问它。如何使其动态或递归,并能够使用相同的文件索引输入?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>M07</title>
</head>
<body>
<?php
$contingut = "";
if($handle = opendir('.')){
while (false !== ($file = readdir($handle))){
if (($file != ".") && ($file != "..") && ($file != "index.php") && ($file != "desktop.ini")){
$contingut .= '<a id="enllaç" href="'.$file.'">'.$file.'</a><br><br>';
}
}
closedir($handle);
}
?>
<?php echo $contingut ?>
$di = new RecursiveDirectoryIterator('.');
foreach (new RecursiveIteratorIterator($di) as $filename => $file)
{
if (($file != ".") && ($file != "..") 
&& ($file != "index.php") && ($file != "desktop.ini"))
{           
echo '<a id="enllaç" href="'.$file.'">'.$file.'</a><br>';
}
}

最新更新