Page 1 of 1

include from root error

Posted: Sun Dec 17, 2006 8:38 pm
by potato
hey everybody,

i'm trying to make a connection to my db with following code:

Code: Select all

require("/Connections/matrix.php");
but then i get following error:

Warning: main(/Connections/matrix.php) [function.main]: failed to open stream: No such file or directory

i want to make it include the file always from the root, so that it doesn't matter in what folder the parentfile is.

Can somebody help me, i'm stucked for hours now with this litlle problem. :oops:

thanx in advance

friendly greetings,
tom

Posted: Mon Dec 18, 2006 3:27 am
by dibyendrah
Is Connections folder on same folder where you are including ?

If that is so, you have to do

Code: Select all

require("Connections/matrix.php");
If it's on on step up from where you are including, it should be

Code: Select all

require("../Connections/matrix.php");
or if it's on the application root folder you are talking about you might need to put the actual path of root folder somewhere so that you can load where ever you are.

Code: Select all

$app_root = "/var/www/my_app/"
OR

Code: Select all

$app_root = "/home/user/public_html/my_app/"
Hope this will help you.

Posted: Mon Dec 18, 2006 3:42 am
by Kieran Huggins
I would use:

Code: Select all

include($_SERVER['DOCUMENT_ROOT']."/path/to/include_file.php");
Cheers,
Kieran

Posted: Mon Dec 18, 2006 7:01 am
by potato
thank you ;)