PHP 列出目录和文件

发布于 2024-07-11 13:03:59 字数 77 浏览 4 评论 0原文

拥有一个页面的最简单方法是什么,该页面将显示用户可以单击打开的目录列表,其中将有更多目录或最终文件可供下载,并使所有这些都发生在同一页面上?

What would be the easiest way to have a page where it will display a list of directories that the user can click on to open, where there will be more directories or eventually files to download and have it all happen on the same page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫性小仙女 2024-07-18 13:04:03

将其放入 .htaccess 文件中:

Options +Indexes

Put this in the .htaccess file:

Options +Indexes
薄荷港 2024-07-18 13:04:01

对于一些基本的东西,您可能最好只将“选项+索引”添加到该文件夹​​的 .htaccess 中。 但是,如果您想要更复杂的东西并且在 PHP5 上运行,您可以使用 目录迭代器 来实现这一点。 最需要考虑的是安全性。

不想只想将目录路径转储到 $_REQUEST 中,然后盲目地让用户加载该目录。 您需要确保采取一​​些安全措施,以防止某些人更改请求并要求查看整个 /var 目录。 执行此操作的最佳方法是仅传递相对于文档根目录的当前文件/文件夹,并确保删除任何 ..,以便有人不能只说 ../../var 或类似的内容。

For something basic you are probably better off just adding 'Options +Indexes' to an .htaccess for that folder. However if you want something more complicated and are running on PHP5 you can use the Directory Iterator to accomplish this. The most important thing to consider is security.

You do not want to just dump the directory path into $_REQUEST and then blindly let the user load that directory. You need to ensure you have some security in place to prevent, for example, some one from just changing the request and asking to see the entire /var directory. The best way to do this is to only pass the current file/folder relative to the docroot and make sure to strip out any .. so some one can't just say ../../var or something similar.

蓝礼 2024-07-18 13:04:00

从文件夹中删除 index.php 并允许在 htaccess 中浏览该文件夹和子文件夹的目录。

To remove index.php from the folder and allow directory browsing for that folder and subfolders in htacceess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文