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 '' 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 ../../

include ('../');
// 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/");
Be a part of the DaniWeb community

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