首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何列出目录的所有内容?

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

Stack Overflow用户
提问于 2010-12-11 10:12:01
回答 2查看 365关注 0票数 1

我想要创建一个index.html文件,它将一个有序列表中目录中的所有文件链接起来。

例如,当您转到这里时,您会发现:

代码语言:javascript
复制
# 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

我想做的事:

代码语言:javascript
复制
<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>

等等..。

EN

回答 2

Stack Overflow用户

发布于 2010-12-11 10:32:01

代码语言:javascript
复制
<?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值,这只是让您入门的一个示例。

票数 1
EN

Stack Overflow用户

发布于 2010-12-11 10:47:53

如何使用PHP从目录中列出文件 回答得太频繁了在这里再次回答。但是,链接上的清单看起来很像Apache的内置目录索引,您可以通过

代码语言:javascript
复制
Options +Indexes

在该文件夹中的.htaccess文件中。请参阅下列链接

  • http://www.cyberciti.biz/faq/enabling-apache-file-directory-indexing/
  • http://httpd.apache.org/docs/2.2/mod/core.html#options
  • autoindex.html
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4416222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档