包括路径和奇怪的结构
哈。 我有一个非常奇怪的网站,现在给我带来了麻烦。 这是简化的结构
public_html
- adm
--- raport
------ raportpdf.php
--- class
------ Bonus
--------- Bonus_DAO.class.php
------ config.php
--- raport.php
- index.php
。 Index.php 是一个巨大的加载器。它有几行:(但我不认为它们有什么区别)
set_include_path('lib/DB' . PATH_SEPARATOR . get_include_path());
set_include_path('lib/PHPLOT' . PATH_SEPARATOR . get_include_path());
set_include_path('config' . PATH_SEPARATOR . get_include_path());
set_include_path('view' . PATH_SEPARATOR . get_include_path());
set_include_path('controller' . PATH_SEPARATOR . get_include_path());
set_include_path('model' . PATH_SEPARATOR . get_include_path());
Bonus_DAO.class.php 内部类似于
require_once('./adm/class/config.php');
Raportpdf.php 是通过 index.php 调用的 - 它在邮件中发送内容而没有任何错误。 但是当我想访问 raport.php 时,出现如下错误:
Warning: require_once(./adm/class/config.php) [function.require-once]: failed to open stream: No such file or directory in /home/panele/domains/blahblah/public_html/adm/class/Bonus/Bonus_DAO.class.php on line 2
Fatal error: require_once() [function.require]: Failed opening required './adm/class/config.php' (include_path='.:/usr/local/lib/php') in /home/panele/domains/blahblah/public_html/adm/class/Bonus/Bonus_DAO.class.php on line 2
我该如何解决这个问题?
Hai.
I've got site which is really weird, and now is making me troubles.
This is simplified structure
public_html
- adm
--- raport
------ raportpdf.php
--- class
------ Bonus
--------- Bonus_DAO.class.php
------ config.php
--- raport.php
- index.php
So. Index.php is giant loader. It has lines: (but I don't think that they are making diffrence)
set_include_path('lib/DB' . PATH_SEPARATOR . get_include_path());
set_include_path('lib/PHPLOT' . PATH_SEPARATOR . get_include_path());
set_include_path('config' . PATH_SEPARATOR . get_include_path());
set_include_path('view' . PATH_SEPARATOR . get_include_path());
set_include_path('controller' . PATH_SEPARATOR . get_include_path());
set_include_path('model' . PATH_SEPARATOR . get_include_path());
Inside Bonus_DAO.class.php is something like
require_once('./adm/class/config.php');
Raportpdf.php is called through index.php - it sends it's content without any error at mail.
But when I want to access raport.php, I have error like:
Warning: require_once(./adm/class/config.php) [function.require-once]: failed to open stream: No such file or directory in /home/panele/domains/blahblah/public_html/adm/class/Bonus/Bonus_DAO.class.php on line 2
Fatal error: require_once() [function.require]: Failed opening required './adm/class/config.php' (include_path='.:/usr/local/lib/php') in /home/panele/domains/blahblah/public_html/adm/class/Bonus/Bonus_DAO.class.php on line 2
How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将如下行插入到您的此结构中包含的文件中(此包含文件必须位于您的根目录中,例如 config.php 或我通常使用 init.php )。
然后,在您收到错误的地方(或者在您的代码中的同义词 - 您需要()/包含()的任何地方),在其前面添加 ROOT_DIR."/path/to/file" 。这样做的目的是提供根目录的绝对路径,然后您只需指定要查找的根目录中的目录即可。例如,我的根目录是“/home2/example”。现在,我将此行插入到我已包含的文件中,并将 require 行更改为:
上面的行基本上翻译成这样(假设我在位于 /home2 的文件中使用了 Define(); 语句/example)
所以基本上,这是一种为静态路径提供动态元素的简单方法,这样您就不会再遇到这个问题了!
祝你好运!
丹尼斯·M.
Insert a line such as the following into a file which is included in this structure of yours (this included file MUST be located in your root directory, something like a config.php or I usually use init.php).
Then, where you are receiving the errors (or for synonymy within your code for that matter - anywhere you require()/include()), add ROOT_DIR."/path/to/file" before it. What this is doing is giving the absolute path to the root directory and then you simply specify the directory within the root which you are looking for. For sake of example, my root directory is "/home2/example." Now, I insert this line in a file which I have included, etc. and change the require line to this:
The line above basically translates out to this (assuming that I used the define(); statement within a file located in /home2/example)
So basically, this is an easy way to give static paths a dynamic element so you won't run into this problem again!
Good luck!
Dennis M.