本文介绍了PHP从webroot外部的文件中包含webroot中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have a php file outside my webroot in which I want to include a file that is inside the webroot.
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');
How can I accomplish this?
解决方案
Full path should be:
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中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!