Jump to content

Include 'root' file from subdirectory


eevan79

Recommended Posts

How to include file from subdirectory?

 

I have tried include '../config.php';

but got error selecting database.

 

Also tried include($DOCUMENT_ROOT."../config.php"); but same result.

 

For example, I have "root/admin" directory, and cant connect (from "/admin" dir)  to database config.php which is in root.There are also other files to include.

Link to comment
Share on other sites

You need to locate that file first... go into dreamweaver (if you have it) and physically find the file. Without a GOOD filepath, we can't help you locate the file.

 

Also, you don't include the "../" when using the $_SERVER['DOCUMENT_ROOT'] function. you are already at the root of the site. so $_SERVER['DOCUMENT_ROOT'] essentially equals www.your-domain.com you can't back up beyond that (well.. not entirely true - but you shouldn't be doing that =^)  ).

 

SO: i would just try require(' $_SERVER['DOCUMENT_ROOT']./config.php') which will drop you in the site root.. the same place as your index (homepage).

Link to comment
Share on other sites

I already tried that:

include($_SERVER['DOCUMENT_ROOT']."./config.php");

and

include($_SERVER['DOCUMENT_ROOT']."config.php");

and many other combinations...but it wont work.

 

That path is on/from localhost. Didnt tested online.

I need to locate path automaticly if its possible. For example to get working directory and go back one level. Is it possible (like in java or c++)?

Link to comment
Share on other sites

Seems your server isn't setup quite right. Whats path is returned when you echo out $_SERVER['DOCUMENT_ROOT']

echo $_SERVER['DOCUMENT_ROOT'];

 

$_SERVER['DOCUMENT_ROOT'] should echo the path to the folder where you place all your files for your site which is served by your http server, eg for Apache it maybe C:/Apache/htdocs, or if you're using IIS most probably C:/Innetpub/public.

 

Can you tell us where your config.php file is located (post full file path)?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.