Re: something annoying about includes/relative paths.
| From: | michael kimsal | Date: | Fri, 10 Jan 2003 04:28:54 +0000 |
| Subject: | Re: something annoying about includes/relative paths. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-131036@lists.php.net to get a copy of this message | ||
Sean Malloy wrote:
Moving to PHP from an ASP backgroun, I always found one thing really annoying about PHP. With ASP, you could have a file structure such as: SYSTEM |--HTML | |--header.asp | |--LOGIC | |--engine.asp | |--core.asp in default.asp, you would <!--#include file="system/core.asp"--> in core.asp, engine.asp would be included as such <!--#include file="LOGIC/engine.asp"--> in engine.asp, header.asp would be included as such <!--#include file="../HTML/header.asp"--> Its a bad example. However, it demonstrates that the relative path for each include changed depending on what file was being included. PHP doesn't do that. Which is kind of annoying, but you get used to it.. But I've come up with a work around. htdocs/index.php include('./system/core.php'); htdocs/system/core.php define('CORE_PATH', str_replace('core.php', '', __FILE__)); include(CORE_PATH.'logic/engine.php'); htdocs/system/logic/engine.php include(CORE_PATH.'html/header.php'); and so on and so forth. searching for __FILE__, and removing the filename from the output, gives you a sort of relative path hack. Hope someone finds that usefulYou could also simply use the $DOCUMENT_ROOT variable prepopulated for you ($_SERVER['DOCUMENT_ROOT'] perhaps?) and base your includes relative to that. Michael Kimsal http://www.phpappserver.com/ 734-480-9961