Home > Backend Development > PHP Tutorial > 关于include路径有关问题

关于include路径有关问题

WBOY
Release: 2016-06-13 12:06:02
Original
1138 people have browsed it

关于include路径问题

如图,我的action.php里引用的写法:include 'class/users.php';
我的uploadpic.php里引用的写法:"../class/users.php";
我的users.php引用连接数据库的写法:include '../admin/class/connect.php';
问题就是users.php引用连接数据库了,如果这样写,action.php会提示连接数据库失败,但uploadpic.php正常!
如果写成include 'admin/class/connect.php';那action.php正常,但uploadpic.php会提示连接数据库失败!
就是路径的问题了,uploadpic.php要返回成上一级才能引用,action.php不需要。
求解决方法!!!
------解决方案--------------------

<br /><br />//在你程序的根目录文件定义<br />define("ROOT_DIR",dirname(__FILE__));<br />例如你的action.php 加入上面定义<br />include ROOT_DIR.'/class/users.php';<br /><br />include ROOT_DIR.'/admin/class/connect.php';<br /><br />
Copy after login

------解决方案--------------------
include 的原则是:
永远是自上而下的引用
所有被引用的文件中的引用都是相对入口文件的相对路径

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template