I have a problem with my path. Say I have a PHP file in /home/bla/www/dev/source/test.php
. In this test.php
file I want to include a file in
/home/bla/www/config/conf.php
<?php
include_开发者_如何学Pythononce("");
?>
I don't want to include it like include
/home/bla/www/config/conf.php
. How can I do it?
PS: This fails:
include_once("../../config/conf.php");
I'd suggest to use an absolute path instead of a relative:
include_once($_SERVER['DOCUMENT_ROOT']."/config/conf.php");
This would work from any folder.
$current_dir = dirname(__FILE__);
require_once($current_dir.'/../foo/bar.php');
Note that require_once('foo.php') looks for foo.php in the same directory as the script, but require_once('../foo.php') is not relative to the path of the script, but relative to the current working directory.
As DaDaDom suggests, permissions may well be the problem here. Have you tried addressing the file using an absolute path (/home/bla/www/config/conf.php
), and if it fails, what's the error?
精彩评论