包括路径和奇怪的结构

发布于 2024-09-10 06:00:22 字数 1367 浏览 10 评论 0原文

哈。 我有一个非常奇怪的网站,现在给我带来了麻烦。 这是简化的结构

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

絕版丫頭 2024-09-17 06:00:22

将如下行插入到您的此结构中包含的文件中(此包含文件必须位于您的根目录中,例如 config.php 或我通常使用 init.php )。

define("ROOT_DIR",dirname(__FILE__));

然后,在您收到错误的地方(或者在您的代码中的同义词 - 您需要()/包含()的任何地方),在其前面添加 ROOT_DIR."/path/to/file" 。这样做的目的是提供根目录的绝对路径,然后您只需指定要查找的根目录中的目录即可。例如,我的根目录是“/home2/example”。现在,我将此行插入到我已包含的文件中,并将 require 行更改为:

require_once(ROOT_DIR."/adm/class/config.php");

上面的行基本上翻译成这样(假设我在位于 /home2 的文件中使用了 Define(); 语句/example)

require_once("/home2/example/adm/class/config.php");

所以基本上,这是一种为静态路径提供动态元素的简单方法,这样您就不会再遇到这个问题了!

祝你好运!
丹尼斯·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).

define("ROOT_DIR",dirname(__FILE__));

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:

require_once(ROOT_DIR."/adm/class/config.php");

The line above basically translates out to this (assuming that I used the define(); statement within a file located in /home2/example)

require_once("/home2/example/adm/class/config.php");

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文