Problems with relative paths in PHP

Status
Not open for further replies.

stodge

Ars Tribunus Militum
1,907
I'm having major problems with relative paths in PHP, when including and requiring files.

I have a

/dev/system/kernel/kernel.php
/dev/system/kernel/includes/config.php

/dev/demo.php

demo.php includes kernel.php, and kernel.php includes config.php.

With the paths being relative, demo.php happily includes kernel.php, but kernel.php won't include config.php because it tries to use the relative path from demo.php and not itself.

I want each file, e.g. demo.php or index.php to only include kernel.php and let the kernel include anything it needs.

Any ideas how to get round this?

Thanks!
 
Well, this would be a fairly clunky way to do it, but how about an if/elseif condition? Time for some psuedocode....
code:<HR>
Code:
if(script == "demo.php")  //demo is in dev dir
   $incpath = "system/kernel/includes/config.php";
else if(script == "index.php") //index is in dev/system dir
   $incpath = "kernel/includes/config.php";

include($incpath);
I hope I got it right, what you wanted.
 
Status
Not open for further replies.