首页 >后端开发 >php教程 > 解决php include中绝对路径与相对路径的有关问题

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-13 12:39:391375浏览

解决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");
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn