0

have a file that is included in a required file. the problem that I am having is the included file work only if the user on pages that are located on the root directory of the site. but if te user branch out to a sub directory they I get the error

failed to open stream: No such file or directory

this is how I currently include the file with in the required file.

include('classes/browser_detection.php')

so I tried couple of thing which did not work

First:

include('/cms/classes/browser_detection.php')

second:

include( dirname(__DIR__) . '/classes/browser_detection.php')

both of those options did not work. How can I get it to work without having to include the class in every page individually where the main file is required?

4

2 回答 2

2

查看答案:PHP 目录 - 最佳实践

我喜欢使用:

config.php(位于根目录中)

define('ROOT_SYS',dirname(__FILE__).'/'); //$_SERVER["DOCUMENT_ROOT"] for root access

这使我可以毫无问题地在本地站点和主机上工作。在您的情况下,它看起来像:

include(ROOT_SYS . 'classes/browser_detection.php')
于 2013-08-21T19:26:33.113 回答
1

您可以设置包含路径

$path = '/home/mywebsite/public_html/cms/classes/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

然后

include('browser_detection.php');
于 2013-08-21T19:27:08.700 回答