自动创建文件结构表示的 PHP 脚本
可能的重复:
PHP - 遍历文件夹并显示 HTML 内容
使用 PHP,我正在尝试创建一个脚本,该脚本将导航到网站的根目录,然后从那里使用 scandir()
或 glob()
(这些是唯一的我学过的目录扫描功能),我将使用递归方法导航根目录中的所有项目,然后在遇到测试为目录的条目时重新调用自身,通过 is_dir($fileName )
。
这就是我遇到问题的地方 - 当我到达一个目录条目时,它正确地将 if 语句导航到目录命令,但是当调用自身时,我似乎无法获取 glob()
目录正确,因为每次我调用它时,页面都会停止加载更多内容。我试图从扫描目录的基于相对 URL 的性质中找出我将如何引用它。我设置了一个变量 $ROOT_DIR
,它是相对于 php 页面所在目录的根目录(在本例中,$ROOT_DIR="../../"
),然后我会从逻辑上思考,我会使用 $ROOT_DIR 调用 scanAllFiles [我的站点地图方法]。 $fileName,这是从字符串中删除前导 "../../"
后找到的目录字符串。尝试了这个之后,还是不行。
我应该使用不同的目录遍历方法来执行此操作,还是我错误地格式化了方法调用?
Possible Duplicate:
PHP - Iterate through folders and display HTML contents
Using PHP, I'm trying to create a script that will navigate to the root directory of a website, and from there, using scandir()
or glob()
(those being the only directory scanning functions I've learned), I would use a recursive method to navigate through all the items in the root directory, then re-calling itself when encountering an entry that tested to be a directory, through is_dir($fileName)
.
Here's where I'm encountering problems - when I reach an entry that is a directory, it correctly navigates the if statement correctly to the commands for directories, but when calling itself, I don't seem to be able to get the glob()
directory right, since every time I call it, the page ceases to load anything more. I'm trying to figure out, from the relative URL-based nature of scanning directories how I would reference it. I set a variable $ROOT_DIR
, which is the root directory relative to the directory in which the php page is located in (in this case, $ROOT_DIR="../../"
), and then I'd think logically, I'd call scanAllFiles [my sitemap method] with $ROOT_DIR . $fileName, where that's the string of the directory found, after removing the leading "../../"
from the string. After trying this, it doesn't work.
Should I be using a different directory-traversing method to do this, or am I formatting the method call incorrectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数人只是使用 MySQL 手动制作站点地图。
公开文件并不安全,但您可以添加一些安全措施。
Most people just use MySQL to make sitemaps, doing it manually.
Exposing files isn't safe, but you can add some security.