include from root error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

include from root error

Post 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
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I would use:

Code: Select all

include($_SERVER['DOCUMENT_ROOT']."/path/to/include_file.php");
Cheers,
Kieran
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

thank you ;)
Post Reply