[英]Open file from a different folder in PHP
Let's say I have two folders in my PHP server root directory: x
and y
. 假设我的PHP服务器根目录中有两个文件夹:
x
和y
。 There are two more directories inside the x
folder: a
and b
. x
文件夹中还有两个目录: a
和b
。 In the /x/a
directory I have the index.php
file and in the /y
folder a stuff.php
file. 在
/x/a
目录中我有index.php
文件,在/y
文件夹中有一个stuff.php
文件。
From my /x/a/index.php
file, I want to include the /y/stuff.php
file. 从我的
/x/a/index.php
文件中,我想要包含/y/stuff.php
文件。 How do I do that? 我怎么做?
My server doesn't allow including files from other domains, so adding the full URL doesn't work! 我的服务器不允许包含来自其他域的文件,因此添加完整的URL不起作用! Also, I'd like to know how to start a path from the root in PHP.
另外,我想知道如何从PHP中的根开始路径。 I use
./blabla
from the index of my root and ../blabla
from directories in the root, but, unfortunately, .../blabla
doesn't work from 2nd grade directories. 我用
./blabla
从我的根和指数../blabla
从目录的根,但不幸的是, .../blabla
不从二年级目录工作。
To access the root begin your path with "/". 要访问root,请以“/”开头。
If you want to go up one directory from where you are currently, eg from /x/a/ to /x/ you could use "../". 如果你想从你当前所在的目录上去,例如从/ x / a /到/ x /你可以使用“../”。
If you want to go back up two directories (eg from /x/a/ to /) you could use "../../" (rather than ".../" which you mentioned). 如果你想要备份两个目录(例如从/ x / a /到/)你可以使用“../../”(而不是你提到的“... /”)。
尝试:
include "../../y/stuff.php";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.