views:

21

answers:

1

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?

+1  A: 

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.

RageD
Thank you! It works like a charm.
Misiur