UniqueData
asked on
include path
I have a file located here:
mySite.com/DataTables/Edit or/php/Boo tstrap.php
There is a line that contains:
include( dirname(__FILE__).'/config .php' );
But I need to use this for various projects that link to different databases and i don't think I want all the files in DataTables in each project folder. So I need config to be in each project folder:
mySite.com/Project1/lib/co nfig.php
mySite.com/Project2/lib/co nfig.php
Instead of using dirname(__FILE__) Is there a way that I can get to the correct project? or is dirname going to return what I want?
mySite.com/DataTables/Edit
There is a line that contains:
include( dirname(__FILE__).'/config
But I need to use this for various projects that link to different databases and i don't think I want all the files in DataTables in each project folder. So I need config to be in each project folder:
mySite.com/Project1/lib/co
mySite.com/Project2/lib/co
Instead of using dirname(__FILE__) Is there a way that I can get to the correct project? or is dirname going to return what I want?
You can (at least) do one of the follwoing:
1) add your library directory to "include_path" directive in php.ini, or
2) without access to php.ini, use relative path in your code, for example, something like: include("../../../library/ config.php ");
1) add your library directory to "include_path" directive in php.ini, or
2) without access to php.ini, use relative path in your code, for example, something like: include("../../../library/
ASKER
but the thing is there will be multiple config files, one in each project folder, each with the connection string for the database for that project.
There is a file is located in mySite.com/DataTables/Edit or/php/Boo tstrap.php , outside of any of the project folders, so that I don't have to copy all the DataTables files into each project folder. Each project will have it's own page that has the statement:
include( "../../DataTables/Editor/p hp/DataTab les.php" );
This DataTables.php is the one with the statement: include( dirname(__FILE__).'/config .php' );
So I need DataTables.php to know that it is being included from mySite.com/Project1/ or mySite.com/Project2/, etc.
So I guess, long story short: how to the path of the file that called it?
There is a file is located in mySite.com/DataTables/Edit
include( "../../DataTables/Editor/p
This DataTables.php is the one with the statement: include( dirname(__FILE__).'/config
So I need DataTables.php to know that it is being included from mySite.com/Project1/ or mySite.com/Project2/, etc.
So I guess, long story short: how to the path of the file that called it?
ASKER
just thought of another way to clarify (I hope)
www.mySite.com/Project1/lib/config.php (contains connection info for database that Project1 uses)
www.mySite.com/Project1/lib/getMathFacts.php
www.mySite.com/Project2/lib/config.php (contains connection info for a different database that Project2 uses)
www.mySite.com/Project2/lib/getStateCapitols.php
each of the "get" php files has the same line:
include( "../../DataTables/Editor/p hp/DataTab les.php" );
www.mySite.com/DataTables/Editor/php/DataTables.php needs to include the config file.
So if it was called from Project1 it includes www.mySite.com/Project1/lib/config.php.
If it is called from Project2 it includes www.mySite.com/Project2/lib/config.php
www.mySite.com/Project1/lib/config.php (contains connection info for database that Project1 uses)
www.mySite.com/Project1/lib/getMathFacts.php
www.mySite.com/Project2/lib/config.php (contains connection info for a different database that Project2 uses)
www.mySite.com/Project2/lib/getStateCapitols.php
each of the "get" php files has the same line:
include( "../../DataTables/Editor/p
www.mySite.com/DataTables/Editor/php/DataTables.php needs to include the config file.
So if it was called from Project1 it includes www.mySite.com/Project1/lib/config.php.
If it is called from Project2 it includes www.mySite.com/Project2/lib/config.php
ASKER
oh my goodness. I can't believe I didn't think of this...
right before I have my include DataTables I set a variable:
$myPath = dirname(__FILE__), which would get the path of the current project
Then, in DataTables I use this in the include:
include( $myPath.'/config.php' );
right before I have my include DataTables I set a variable:
$myPath = dirname(__FILE__), which would get the path of the current project
Then, in DataTables I use this in the include:
include( $myPath.'/config.php' );
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://php.net/manual/en/function.dirname.php
http://php.net/manual/en/language.constants.predefined.php
In the case with __FILE__, php says, "The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned."