note 19516 deleted from function.include by sniper

From: Date: Wed, 29 Jan 2003 04:07:51 +0000
Subject: note 19516 deleted from function.include by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-42979@lists.php.net to get a copy of this message
I built a custom function to accomodate for relative includes from within nested includes (the old a includes b includes c problem mentioned a couple times above). Use this in place of PHP's include() function every time, and you can always include a file relative to the current file you are in. Ex: myInclude("deep/nested/include/file.php") <?php function myInclude($fileName) { //you are here $rootPath = getcwd()."/"; //find where we need to go $aryFilePath = split("/", $fileName); $fileToInclude = array_pop($aryFilePath); $includePath = join("/", $aryFilePath) . "/"; //do the include chdir($rootPath.$includePath); include($fileToInclude); chdir($rootPath); } ?> Hope this helps someone...

« previous php.notes (#42979) next »