PHP包含路径错误

时间:2010-12-02 20:21:37

标签: php

当我尝试在include_path中包含simpletest时,我一直收到错误:

<?
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(basename(dirname(__FILE__)) . '/../../'));

include 'simpletest/autorun.php';

返回:

.:/usr/lib/php:/Users/kristiannissen/Documents/php
Warning: require_once(/Users/kristiannissen/Documents/php/simpletest/arguments.php): failed to open stream: No such file or directory in /Users/kristiannissen/Documents/php/simpletest/reporter.php on line 13

Fatal error: require_once(): Failed opening required '/Users/kristiannissen/Documents/php/simpletest/arguments.php' (include_path='.:/usr/lib/php:/Users/kristiannissen/Documents/php') in /Users/kristiannissen/Documents/php/simpletest/reporter.php on line 13

2 个答案:

答案 0 :(得分:1)

个人首先执行您的查看页面,例如index.php和查看页面应始终位于您的html的根目录中。

所以在index.php中你可以这样做:

define("BASE_PATH",str_replace("\\","/",dirname(__FILE__)));

所以现在BASE_PATH将等于:/Users/kristiannissen/Documents/php/simpletest

因此,如果您想要在包含路径中使用php目录,则应使用dirname()转到 UP 目录:

//Get an array of your include paths
$include_parts = explode(PATH_SEPARATOR,get_include_path());

//Extend the paths
$include_parts[] = dirname(dirname(BASE_PATH)); //this is ../../

//recompile the paths and set them
set_include_path(implode(PATH_SEPARATOR,$include_parts));

这是完成您尝试做的事情的安全方式。

答案 1 :(得分:1)

sourceforge上有一个alpha2版本,其中arguments.php-require被注释掉了。我想这不再需要了。