PHP中的require_once()函数引入的文件找不到
2016-10-09 11:30
435 查看
今天用php写一个简单的Android登录的服务端代码,遇到一个特别郁闷的事,使用require_once()引入到php文件中的文件出现错误提示,找不到文件。
php中的require_once()主要用来将一个php文件引入另一个php文件中,我先说说我遇到的问题,我的目录结构是这样的:
我在user.class.php中是这样写的:
看起来确实不错,但是我又在index.php中引入了user.class.php
代码看起来也是不错的,然而运行报了下面的错:
想了一下终于发现问题所在:
require_once()函数其实是将你包含的文件的代码放到了你引用的位置,也就是说,经过上面两次引用,其实现在在index.php文件中是这样的
然后index.php又按照这个路径去找这两个文件,自然就找不到了。
看来在实际开发中还是要慎用相对路径。
php中的require_once()主要用来将一个php文件引入另一个php文件中,我先说说我遇到的问题,我的目录结构是这样的:
我在user.class.php中是这样写的:
require_once("../config/mysqlConfig.php"); require_once('../util/HandleMysql.class.php');
看起来确实不错,但是我又在index.php中引入了user.class.php
require_once("class/user.class.php");
代码看起来也是不错的,然而运行报了下面的错:
想了一下终于发现问题所在:
require_once()函数其实是将你包含的文件的代码放到了你引用的位置,也就是说,经过上面两次引用,其实现在在index.php文件中是这样的
require_once("../config/mysqlConfig.php"); require_once('../util/HandleMysql.class.php');
然后index.php又按照这个路径去找这两个文件,自然就找不到了。
看来在实际开发中还是要慎用相对路径。
相关文章推荐
- PHP各种引入文件函数的执行效率include require fpassthru readfile
- php require_once()引入文件后,后面的代码无法执行
- PHP包含文件函数include、include_once、require、require_once区别总结
- PHP包含文件函数include、include_once、require、require_once区别总结
- PHP包含文件函数include、include_once、require、require_once的使用
- PHP包含文件函数include、include_once、require、require_once区别总结
- PHP各种引入文件函数的执行效率include require fpassthru readfile
- PHP各种引入(读取)文件函数的执行效率include require fpassthru readfile等的性能比较
- PHP包含文件函数include、include_once、require、require_once区别总结
- [乐意黎原创] PHP文件包含语句 include、include_once、require、require_once的区别
- php------include和require都能把另外一个文件包含到当前文件中,区别是什么,include和include_once区别?
- php学习笔记6--php中的文件包含 include,require,include_once,require_once
- php include()、 include_once()、 require() 、 require_once() 函数直接的区别
- PHP包含文件(require/include/require_once/include_once/__autoload/spl_autoload_xxx)分析总结
- PHP文件包含语句 include、include_once、require、require_once
- PHP文件包含语句 include、include_once、require、require_once
- php之文件载入include, include_once,require,require_once
- php中文件引入require
- 函数中使用require_once问题深入探讨 优雅的配置文件定义方法推荐
- PHP文件包含语句 include、include_once、require、require_once的区别