开发者

PHP include path error

开发者 https://www.devze.com 2023-01-28 06:39 出处:网络
I keep getting an error when I try to include simpletest in my include_path: <? set_include_path(get_include_path() . PATH_SEPARATOR . realpath(basename(dirname(__FILE__)) . \'/../../\'));

I keep getting an error when I try to include simpletest in my include_path:

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

include 'simpletest/autorun.php';

returns:

.:/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/开发者_StackOverflow中文版lib/php:/Users/kristiannissen/Documents/php') in /Users/kristiannissen/Documents/php/simpletest/reporter.php on line 13


personally your view pages are the first executed, such as index.php and view pages should always be in the root of your html.

so within index.php you can do:

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

so now BASE_PATH would be equal to: /Users/kristiannissen/Documents/php/simpletest

So if you want to phpdirectory in your include path you should use dirname() to go UP a directory:

//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));

this is the safe way to accomplish what your trying to do.


There is an alpha2-release on sourceforge that has the arguments.php-require commented out. I guess it isn't needed anymore.

0

精彩评论

暂无评论...
验证码 换一张
取 消