Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

following is my files directory structure...

Config
   config.php (is calling some files too like includes/class.DB.php)

Now i have created another folder Admin and created new config.php (and calling root config file by require_once '../config/config.php';) its loading config file correctly but showing errors on includes/class.DB.php .

I hope, you have got my an idea of my problem, what is the way to achieve this, by USING DIR_NAME/ $SERVER['DOCUMENT_ROOT']

please help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
468 views
Welcome To Ask or Share your Answers For Others

1 Answer

use

dirname(__FILE__); // or, if you have +5.3, use __DIR__ instead

so if you have this structure

includes
    -class.php
admin
    -admin.php
config
   -config.php

So you can use

//admin.php
include(dirname(__FILE__)."/../config/config.php");

//config.php
include(dirname(__FILE__)."/../includes/class.php");

it always aims to the same directory!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...