我想制作一个 index.html 文件,它以有序列表的形式链接目录中的所有文件。
例如,当你去here ,你会发现:
# Parent Directory
# <u>lol.html
# "><script>alert(String.fromCharCode(72)-String.fromCharCode(105)).html
# -AAAAAAAAAAAAAAAAAAAATESTING.html
# 0dl.blogspot.com.html
# 1000-suns.html
# 123-greeting.html
# 151.html
# 1^2+2-.-2^2-+-3^2-+2-.-4^2.html
# 2010-IIT-JEE-Solutions-Fiitjee.html
# 2010-IIT-JEE-Solutions.html
我想做什么:
<a href="http://searchr.us/web-search/<%3bu>%3blol.html" ><u>lol.html</a>
<a href="http://searchr.us/web-search/"%3b>%3b<%3bscript>%3balert(String.fromCharCode(72)-String.fromCharCode(105)).html">http://searchr.us/web-search/"%3b>%3b<%3bscript>%3balert(String.fromCharCode(72)-String.fromCharCode(105)).html</a>
等等……
最佳答案
<?php
$dir = getcwd();
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo '<a href="'.$_SERVER['REQUEST_URI'].'/'.$file.'">' . $file . '</a><br />';
}
closedir($dh);
}
}
?>
注意必须更改 a 标签的 href 值,这只是一个帮助您入门的示例。
关于php - 如何列出目录的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4416222/