include,require的文件包含是以当前工作目录寻找,也就是把当前文件作为参照.
例如
文件的多层包含问题就会容易出错。
eg:
“smarty_test/system/system.inc.php”;
"smarty_test/smarty/smarty.class.php";
"smarty_test/index.php";
在system.inc.php中有代码:include "../smarty/smarty.class.php";
如果index.php中有用到include "system/system.inc.php";
这时候就会出错,因为include,require是把当前文件桌作为参照。
解决方案思考1:
如果用$_SERVER['PHP_SELF']来代替文件自身路径;
如果在system.inc.php中用$_SERVER['PHP_SELF'];
那么当在index.php中include "system/system.inc.php"时,system.inc.php却显示的是index.php的地址。
所以方案想不通
解决方案2
用__FILE__
如上,文件无论如何被include,__FILE__都显示的是自身文件的地址