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
https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/
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).

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++)?

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)?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.