PHP包含来自webroot外部文件的webroot文件 [英] PHP include file in webroot from file outside webroot

查看:170
本文介绍了PHP包含来自webroot外部文件的webroot文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a php file outside my webroot in which I want to include a file that is inside the webroot.


webroot之外的文件夹

- >我要包含的php文件

webroot

- >要包含的文件

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

所以我必须去一个目录,但这不起作用:

So I have to go one directory up, but this doesnt work:

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

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

Include full path doesn't work either:

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

我该如何做到这一点?

推荐答案

完整路径应为:

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

或者您应该设置如下路径:

Or you should set the path like:

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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆