简体   繁体   中英

PHP list directories and files

最简单的方法是在一个页面上显示一个目录列表,供用户单击以打开目录,在该页面上将有更多目录或最终文件可供下载,并全部显示在同一页面上?

从文件夹中删除index.php并允许目录浏览该文件夹及其htacceess中的子文件夹。

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.

将其放在.htaccess文件中:

Options +Indexes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM