我尝试了很多方法来解决这个问题,但仍然不起作用。
操作系统:debian wheezy
我在运行php5.4.4
我有一个文件tester.php,其中包含test1.php和test1包含test2.php。
我只能使用include_once $_SERVER['DOCUMENT_ROOT']."/test2/test2.php";
在test1.php
我不能使用include_once "../test2/test2.php";
,大家能告诉我为什么吗?
错误信息:
Warning: include_once(../test2/test2.php): failed to open stream: No such file or directory in /var/www/test1/test1.php on line 2 Warning: include_once(): Failed opening '../test2/test2.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/test1/test1.php on line 2
tester.php
<?php
include_once "test1/test1.php";
echo "tester";
?>
test1.php
<?php
include_once "../test2/test2.php";
echo "test1";
?>
test2.php
<?php
echo "test2";
?>
结构:
+-test1/
| |
| +---- test1.php
|
+-test2/
| |
| +---- test2.php
|
--tester.php
谁能告诉我如何解决这个问题?多谢。
try:
包括(目录名(文件)。/test.php);
或
define('PATH','/home/devp/public_html/project/includes');
include(PATH.'/test.php');
当你调用include_once './../test2/test2.php';
时,这基本上告诉你走出一个文件夹,在/test2/
中打开test2.php
如果您想包含test2.php
,例如tester.php
,路径将是:./test2/test2.php
注意: ./
表示相对于当前路径,您不需要它,而只是一个首选项。