php中include,require的文件包含问题,以及$_SERVER['PHP_SELF']和__FILE__的区别


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__都显示的是自身文件的地址








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值