[英]Custom directory viewer (php)
I started a little project a few days ago, a directory viewer . 几天前,我开始了一个小项目,一个目录查看器 。 (Not a redesigned htaccess thing.)
(不是重新设计的htaccess东西。)
It's written in PHP and works great except for a few little things. 它是用PHP编写的,除了一些小东西外,效果很好。
I have one file ( masterfile ) where all parts of the viewer (css, php, ..) come together and build the final viewer. 我有一个文件( masterfile ),其中查看器的所有部分(css,php,..)聚集在一起并构建最终的查看器。 Whenever you access a directory without an
index.php
, index.html
, etc. in it, you should end up in this masterfile and see your directory (-content). 每当访问目录中没有
index.php
, index.html
等的目录时,都应进入该主文件并查看目录(-content)。
Example: example.com/css/ => You're in css dir => Show custom dir viewer (css folder) 示例:example.com/css/ =>您在CSS目录中=>显示自定义目录查看器(css文件夹)
Idea: Disable .htaccess
indexing which produces an 403 error, redirect this error to masterfile. 想法:禁用
.htaccess
索引,该索引会产生403错误,然后将此错误重定向到masterfile。
Options -Indexes
ErrorDocument 403 /masterfile.php
This does work, however it lists the content of the masterfile directory and not the content from original folder (example: /css/
) Ideas? 确实可以,但是它列出了masterfile目录的内容,而不是原始文件夹中的内容(例如
/css/
)。
Possible solution (I don't like): Put a file, that includes this "masterfile", in EVERY directory and name it index.php 可能的解决方案(我不喜欢):将包含此“ masterfile”的文件放在每个目录中,并将其命名为index.php
I hope you guys have some ideas, I appreciate any help! 希望你们有一些想法,感谢您的帮助!
You can put something like this at the top of masterfile.php
: 您可以将以下内容放在
masterfile.php
的顶部:
$parsed = parse_url($_SERVER['REQUEST_URI']);
$files = scandir($_SERVER['DOCUMENT_ROOT'].$parsed['path']);
maybe with some adjustment depending of your server configuration. 可能需要进行一些调整,具体取决于您的服务器配置。 The
parse_url
stuff is to remove eventual GET
and/or segments. parse_url
内容是删除最终的GET
和/或段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.