加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP包含来自webroot外部文件的webroot文件

发布时间:2020-12-13 17:43:10 所属栏目:PHP教程 来源:网络整理
导读:我在我的webroot外面有一个php文件,我想在其中包含一个webroot内的文件. folder outside webroot – php file in which I want to include webroot – file to include 所以我必须去一个目录,但这不起作用: include('../webroot/file-to-include.php'); 包
我在我的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读