I have an application that is broken up into several sites with common files. The structure looks like this...
|
|--[Site A] <--Web site A points here
| |-- (Files and folders)
|
|--[Site B] <--Web site B points here
| |-- (Files and folders)
|
|--[Includes] <--common files are here
If I am in Site A or B and I do something like this:
require_once(include.php)
everything works fine, but if I do this:
require_once(../Includes/include.php)
I get an error.
I am getting around that by doing some legwork to parse the path, such as
$path = explode( "\\" , __DIR__ );
for ($i = 1; $i <= 2; $i++) { array_pop( $path ); }
$path = implode( "\\" , $path ) . "\\includes\\initialize.php" ;
While this works, I am looking for a more elegant solution using require_once()
thanks.
are you sure the script that contains "require_once" is in [Site A] and not in a subfolder of it? I'm asking because path is relative to the including script. for example, if you have an Index.php file in site A that includes "/subfolder/config.php" and you want config.php include something outside site A, you would have to use
require_once(../../Includes/include.php)
require_once(../Includes/include.php)
-- are the missing quotes a typo or is that what the real code looks like - Jon 2012-04-04 20:38