我的 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/