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?

Recommended Answers

All 2 Replies

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");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.