PHP列表目录和文件 [英] PHP list directories and files

查看:128
本文介绍了PHP列表目录和文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最简单的方法是让一个页面显示用户可以点击打开的目录列表,其中会有更多的目录或最终要下载的文件,并将它们全部发生在同一页面上

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?

推荐答案

对于一些基本的东西,你可能会更好地为该文件夹的.htaccess添加选项+索引。但是,如果您想要的东西更复杂,并且在PHP5上运行,您可以使用目录Iterator 完成这个。要考虑的最重要的事情是安全性。

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.

不要想将目录路径转储到$ _REQUEST中,然后盲目地让用户加载该目录。您需要确保您具有一定的安全性,以防止例如某些只是更改请求并要求查看整个/ var目录。最好的方法是只传递当前文件/文件夹相对于docroot,并确保删除任何..所以有些人不能只说../../var或类似的东西。

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.

这篇关于PHP列表目录和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆