PHP 从 webroot 之外的文件中包含 webroot 中的文件

标签 php include

我的 webroot 外有一个 php 文件,我想在其中包含 webroot 内的文件。

folder outside webroot
- > php file in which I want to include
webroot
- > file to include

所以我必须向上移动一个目录,但这不起作用:

include('../webroot/file-to-include.php');

包括完整路径也不起作用:

include('home/xx/xx/domains/mydomain/webroot/file-to-include.php');

我怎样才能做到这一点?

最佳答案

完整路径应该是:

include('/home/xx/xx/domains/mydomain/webroot/file-to-include.php');

或者你应该像这样设置路径:

include(__DIR__ . '/../webroot/file-to-include.php');  // php version >= 5.3
include(dirname(__FILE__) . '/../webroot/file-to-include.php');  // php version < 5.3

关于PHP 从 webroot 之外的文件中包含 webroot 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13550471/

相关文章:

php - 如何在 linux 主机中运行 php 套接字服务器

php - 在 php 中编辑字符串

c++ - 使用多个头文件和 cpp 文件帮助

c++ - C++ 中的相互包含 .. 它是如何工作的?

iphone - 奇怪,包括 AFNetwork 的问题?

c++ - 包括库 C++

javascript - CakePHP 3 : Ajax response is returning a 200 response code and a parsererror

javascript - 如何使用 AJAX 在 Javascript 中对 PHP 数组进行索引?

php - CakePHP:findById 返回不正确的行?

c++ - C++项目的结构应该是什么?