简体   繁体   English

是否可以在PHP scandir中使用相对路径,并且身份验证会影响scandir吗?

[英]Is it possible to use relative paths with PHP scandir and does authentication affect 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. 我只需要/admin/galleries/目录中的目录的简单列表。 I'm trying to use scandir. 我正在尝试使用scandir。

$folderlist = scandir("../../admin/galleries");

This doesn't return false , but it returns empty. 这不会返回false ,但是会返回空。 I'm not sure why? 我不确定为什么吗? Is it the authentication on that directory that's blocking access via scandir? 是该目录上的身份验证阻止了通过scandir的访问吗? I wouldn't have thought that would have affected a server process like scandir. 我不会想到这会影响像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. 当我在/guest/access/内部创建一个虚拟目录并将scandir路径更改为scandir(".") ,它将输出该目录的名称。 But if I move that same directory up into the /guest/ directory and change scandir to scandir("..") or scandir("../../guest") , it returns empty again. 但是,如果我将同一目录上移到/guest/目录,然后将scandir更改为scandir("..")scandir("../../guest") ,它将再次返回空。 That makes me think it's not an authentication problem, but something with scandir itself? 这使我认为这不是身份验证问题,而是scandir本身有问题吗?

尝试在/../../之前使用dirname(__FILE__)

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. 它没有返回空值,我只是没有将正确的相对路径合并到我的echo语句中,而是通过is_dir()语句运行它们,该语句返回false,因为这些目录在本地目录中不存在。 Dumb mistake. 愚蠢的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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