Home >Backend Development >PHP Tutorial > 解决php include中绝对路径与相对路径的有关问题

解决php include中绝对路径与相对路径的有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:39:391386browse

解决php include中绝对路径与相对路径的问题
在使用php的include/require/include_once/require_once时有时会碰到路径困扰,尤其是重复包含或嵌套包含时,一个有效的办法是定义文件“根”,如:

if (!defined('KEIYICLASS_ROOT')) {

define('KEIYICLASS_ROOT', dirname(__FILE__) . '/');

}


// core classes

include_once(KEIYICLASS_ROOT."core/date.php");

include_once(KEIYICLASS_ROOT."core/db.php");

include_once(KEIYICLASS_ROOT."core/init.php");

include_once(KEIYICLASS_ROOT."core/sys.php");
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn