0

The title says it all. I want to include a file outside the current working directory.

Suppose my file is in the address "localhost/directory1/directory2" and I want to include 'core.inc.php' located in "localhost/directory1".

In this case is requiring that file possible? If so then how can I achieve this?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ddymacek
0

I didn't follow the link posted by psych..
2 quick ways. if you are one directory above say localhost/dir1/dir2
you can reference dir1 with ../ and localhost with ../../
so:

include ('../core.inc.php');
// another way is to use your environment variable for your server.
//just do an echo $_SERVER['DOCUMENT_ROOT'];  
// and you can set your 'direct' paths up off of the 
// will give you the base path to your web directory, I believe in your case would be localhost.
include($_SERVER['DOCUMENT_ROOT'] . "/directory1/core.inc.php");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.