我有一个名为users的文件夹。用户包含:
*username*/index.php
member.php
*username*
是已注册的用户的用户名。有几个*username*
个文件夹,它们都包含index.php。
由于*username*/
中的index.php已超过member.php
,如何在不使用整个网址的情况下在member.php
中加入index.php
?我已经尝试了users/member.php
和/users/member.php
,但它说该目录不存在。我不能使用整个URL,因为它弄乱了我的PHP。如何在不使用整个网址的情况下添加member.php
?
答案 0 :(得分:3)
只要username / index.php不更改当前工作目录,您只需使用相对路径:
include '../members.php';
如果它确实改变了cwd,只需要包含cwd的相对路径。您可以通过以下方式找出脚本的当前工作目录:
echo getcwd();
答案 1 :(得分:0)
在文件系统中,字符串../
表示上一个目录。
include("../members.php");
答案 2 :(得分:0)
这个结构听起来很奇怪。无论如何,你可以使用
include __DIR__.'/../member.php'
您也可以使用简单的
include '../member.php'
但仅当index.php是您启动脚本时(即您在浏览器中键入的内容以启动应用程序)