Sean, et al -- ...and then Sean Malloy said... % ... % % 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
Not only does one get used to it, but one might have preferred it that way in the first place :-) % 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'); I've come up with the following trick for files being tested in a development environment. In general, we have $ cat index.php <?php include("/home/sites/.php/devel/index.inc";)?> $ cat other.php <?php include("/home/sites/.php/devel/other.inc";)?> where /devel might be missing (for production code) or /test (for a test version) or anything else for some devel offshoot. There are various files included within index.inc, and we of course want to get the right copies. So in index.inc and other.inc and any other files, I have a short # this will let us figure out where we are and then always source the right include stuff! # it does not work with symlinks (__FILE__ reports the *target*) # you must have a full env tree in your devel tree; we now look exclusively in $DEVELDIR if set if ( ereg("/home/sites/\.php/",__FILE__) ) # are we *somewhere* in our usual master tree? { $DEVELDIR = preg_replace("|/.*/home/sites/\.php(.*)/[^/]*$|","\\1",__FILE__) ; } # get the working dir followed by include("/home/sites/.php$DEVELDIR/includestuff.inc"); # include our various files where includestuff.inc looks like # config settings and functions and the like foreach ( array ( "config.php" , "functions.inc" ) as $incfile ) { foreach ( array # (this could be quite long) ( "/home/sites/.php$DEVELDIR", # host-wide dir "$_SERVER[DOCUMENT_ROOT]", # web-site-wide dir getcwd() # this job ) as $dir # what do we call it? ) { if ( file_exists ("$dir/$incfile") ) # is there a script file? { include ("$dir/$incfile") ; } # well, include it! } } and, as you can see, gets the master config.php and functions.inc from the proper devel tree (as well as then from the doc root and the script dir), and any other includes down in the script point the same way like include ("/home/sites/.php$DEVELDIR/index.table.inc"); # magic auto-table code or so. It's hard-coded to our central directory (/home/sites/.php) but you have to write these things down somewhere :-) % ... % Hope someone finds that useful Same here :-) HTH & HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
msg92420/pgp00000.pgp
Description: PGP signature