php - 如何列出目录的所有内容?

标签 php javascript html

我想制作一个 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/&lt%3bu&gt%3blol.html" >&lt;u&gt;lol.html</a>
<a href="http://searchr.us/web-search/&quot%3b&gt%3b&lt%3bscript&gt%3balert(String.fromCharCode(72)-String.fromCharCode(105)).html">http://searchr.us/web-search/&quot%3b&gt%3b&lt%3bscript&gt%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/

相关文章:

javascript - eq(0) 不是 $.each 的有效选择器

jquery - 我的 div 标签在 jquery.html 替换后没有正确对齐

javascript - HTML - 我无法在 Internet Explorer 中由 javascript 动态显示的某些文本框中写入

php - 正则表达式删除除括号之间的所有空格

php - 将电子邮件保存到 MySQL 供员工 CRM 使用

javascript - JavaScript MouseEvent 中的 e.metaKey 指的是哪个键?

javascript - 如何在 Javascript 中对数组值使用 split() 方法?

jquery - 裁剪器 JS : Positioning/size issue inside Bootstrap modal

javascript - 使用 PHP 和 AJAX 从 MySQL 数据库选择和检索数据

php - Group_concat 然后将其分解成一个数组