Harry: Includes mit relativem Pfad innerhalb von includeten Dateien

Beitrag lesen

n'Abend

Die Lösung zu Deinem Problem steht in den Benutzeranmerkungen zu include():

--------schnipp zitat von php.net------------
I had a problem with the "include". One of PHP's biggest
problems is that if (as someone previously noted) if file A includes file
B and file B wants to include file C and the files are in different
directories there can be complications, because file B's include path
automatically shifts to whatever file A's may be. A bit confusing to say
the least. But there is hope!

You can work around this problem by creating one page in every directory
and sub-directory of your project. Name this file "path.php" in
every directory. In path.php simply put:

define("BASE", "path-to-root-project-directory");

then, at the top of every php page, before any other includes, include
path.php.

Then, before any include statements, use the BASE global.

include "library.php" becomes:
include BASE."library.php"

Now you simply structure all includes to be relative to the project's base
directory, and every page will know how to get there. This explanation
makes it sound worse than it is.

Hope this helps someone out there.
--------------schnipp-------------------
(c) ryanflynnn@hotmail.com

http://www.php.net/manual/en/function.include.php

Ciao,

Harry