Link to home
Start Free TrialLog in
Avatar of micamedia
micamedia

asked on

Include without full hard coded path

I have the following include

include "/home/voteforp/public_html/core/conf.php";


I have to hard code the path, because the file that uses this include, is called from all sorts of folders. I thought I could just do the following:

include $_SERVER["DOCUMENT_ROOT"]."code/conf.php";

which worked when calling the php files over the web in the normal way. But i have to call them from the command line as well via an exec call. When i try to run the page from a command line call (eg: "php myscript.php") the include line doesn't work unless i hard code the full path.

The reason why i can't hard code it, is that this entire application will be moved to various other home folders. I'd have to change the hard coded path each time I installed it in a new directory. I don't want to have to do that.

Anyone have any ideas of how I can do this?
Avatar of Promethyl
Promethyl
Flag of United States of America image


What about:
<?
chdir ("/myprogrampath/");
shell_exec("php -q ". getcwd(). 'myprogram.php');

?>
Avatar of micamedia
micamedia

ASKER

what is that going to do for me? I still have to know the full program path.. that point is that i'm trying to make it working WITHOUT having to have code in the full program path

Actually i the file "core/conf.php" has the full program path as a configuration variable. I don't mind having to put it there, but I don't want to have to put it anywhere else. The problem I am having is how do I get all the scripts to be able to find the configuration file without having to put the full path in the include..

Like i said  $_SERVER["DOCUMENT_ROOT"]."core/confi.php"   finds the path just fine unless i run the file via the command line..

is $_SERVER["DOCUMENT_ROOT"] different when running from the command line?

ASKER CERTIFIED SOLUTION
Avatar of incrediblejohn
incrediblejohn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: incrediblejohn {http:#13869661}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Huji
EE Cleanup Volunteer
No objection here! Thank you!