Reply to Re: [PHP] Re: Include path quirks

Your name:

Reply:


Posted by Edward Vermillion on 07/18/05 23:47

Ethilien wrote:
> Actually, I think I might have found a solution, although its not a very
> good one.
>
> include realpath(dirname(__FILE__) . "/" . "../include/global.php");
>
> Ethilien wrote:
>
>> I've been attempting to write an application with a bit more ordered
>> directory structure than I normally use, and I ran into the rather
>> annoying problem with include() where relative paths are only based
>> off of the current working directory, and not that of the included
>> script. This makes it impossible to include script correctly, because
>> the path from the working directory is different than that of the
>> included file.
>>
>> The problem is I'm trying to include
>> /include/global.php
>>
>> from
>> /elements/nav.php
>>
>> but topnav is included by
>> /index.php
>>
>> Which results in a failed top open stream error. Is there any way
>> around this annoying idiosyncrasy?
>
>

What I do, and a lot of other folks I borrowed the idea from, is to set
a variable or constant, something like

define('INCLUDE_DIR', "include/")

in your index, or init file. Then when you need to do an include from
another included file you just do include INCLUDE_DIR."somefile.php" and
the path is set for you.

All file paths are going to be relevant to the first script hit, so you
can change the actual path to your include directory relative to that
script.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация