是否可以在 PHP scandir 中使用相对路径,身份验证是否会影响 scandir?
我的网站中有一个经过身份验证的目录,其中有一堆照片目录。如果您登录,则可以访问这些照片。
/admin/galleries/
我想在该目录之外构建另一个页面,我可以授予来宾访问权限以查看经过身份验证的目录中的目录列表。
/guest/access/
我只需要 /admin/galleries/
目录中的目录的简单列表。我正在尝试使用 scandir。
$folderlist = scandir("../../admin/galleries");
这不会返回 false
,但会返回空。我不知道为什么?是该目录的身份验证阻止了通过 scandir 的访问吗?我没想到这会影响像 scandir 这样的服务器进程。
是不是相对路径有问题?当我在 /guest/access/
内创建一个虚拟目录并将 scandir 路径更改为 scandir(".")
时,它会输出该目录的名称。但是,如果我将同一目录移至 /guest/
目录并将 scandir 更改为 scandir("..")
或 scandir("../. ./guest")
,它再次返回空。这让我认为这不是身份验证问题,而是 scandir 本身的问题?
I have an authenticated directory in my site that has a bunch of directories of photos in it. If you log in you can access these photos.
/admin/galleries/
I want to build another page outside of that directory that I can grant guest access to viewing the list of directories in the authenticated directory.
/guest/access/
I just need a simple list of the directories in the /admin/galleries/
dir. I'm trying to use scandir.
$folderlist = scandir("../../admin/galleries");
This doesn't return false
, but it returns empty. I'm not sure why? Is it the authentication on that directory that's blocking access via scandir? I wouldn't have thought that would have affected a server process like scandir.
Is the relative path a problem? When I make a dummy directory inside of /guest/access/
and change the scandir path to scandir(".")
, it outputs that directory's name. But if I move that same directory up into the /guest/
directory and change scandir to scandir("..")
or scandir("../../guest")
, it returns empty again. That makes me think it's not an authentication problem, but something with scandir itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在
/../../
之前使用dirname(__FILE__)
Try to use
dirname(__FILE__)
before your/../../
很抱歉这个问题这么长时间没有得到解答:
它没有返回空,我只是没有将正确的相对路径合并到我的 echo 语句中,并通过返回 false 的 is_dir() 语句运行它们,因为这些目录没有存在于本地目录中。愚蠢的错误。
Sorry to have left this question unanswered so long:
It wasn't returning empty, I just hadn't incorporated the correct relative path into my echo statements and had run them through an is_dir() statement that returned false because those directories didn't exist in the local directory. Dumb mistake.