"Daniel Silva" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Php.Net wrote:
> > The way PHP handles includes is very weird, for example:
> >
> > - create a folder, name it f ex "includes"
> > - create 2 sub-folders, call them level1 and level2
> > - now lets create a file, "includes.php"
> >
> > includes.php
> > ----------------------------------------------
> >
> > <?
> > echo "testing";
> > ?>
> >
> > ----------------------------------------------
> >
> > - now create 3 dummy files, name them dummy.php and distribute
> > them through each folder, in each dummy.php include "includes.php"
> >
> > <?
> > include_once ( 'includes.php' );
> > ?>
> >
> > <?
> > include_once ( '../includes.php' );
> > ?>
> >
> > <?
> > include_once ( '../../includes.php' );
> > ?>
> >
> > - now in the dummy.php on the last level, include the dummy.php
> > from the level below
> >
> > <?
> > include_once ( '../../includes.php' );
> > include_once ( '../dummy.php' );
> > ?>
> >
> > - now try to run dummy.php from the last level ( the one with 2 includes
> > ), what do you get ? a nice message error stating
> >
> > Warning: main() [function.include]: Failed opening '' for inclusion
> > (include_path='.;C:\php5\pear') in
> > D:\shared\www\includes\level1\dummy.php on line 2
> >
> > it's like php processes the first include relative path, goes down the
> > file system tree, stays there and then caches the path, because it
> > doesn't reset to the including script path, it just stays there ...
> >
> > this is very fustrating when you must/want to include one or more files
> > in every script, and you have several folders and sub-levels.
> >
> > there are several workarounds, like out them in a common folder, and add
> > it to the include_path either directly in php.ini or using ini_set(),
> > but that would be a real pain in the arse ...
> >
> > solutions ?
> >
> > regards,
> > idss
>
> Before anyone asks me, yes, the behaviour is the same even with the use
> of include_once ou require_once =)

The only workaround I see is using a full system path. You could define it
in a config file as a constant:
define('DIR_INCLUDE', '/path/to/your/file/');

Then use it in your scripts:
include_once DIR_INCLUDE . 'file.php';
include_once DIR_INCLUDE . 'file2.php';

HTH,
Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to