Reply to Re: Using Relative Paths With include()

Your name:

Reply:


Posted by Jerry Stuckle on 11/16/05 15:13

MBS wrote:
> "J.O. Aho" <user@example.net> wrote in
> news:3u0mikFuo1hoU1@individual.net:
>
>
>>MBS wrote:
>>
>>>I am playing around with some PHP code. I want to put in an
>>>include() function so I can include existing HTML code and output it
>>>to the browser.
>>>
>>>Lo and behold PHP does not support relative paths with the include()
>>>function! (How shortsighted can you get?) Is there any way at all
>>>to use relative paths with include()? Any hacks? If I use an
>>>absolute filepath, everything is fine. But I don't want to do
>>>that--I can't do that. I want to use the filepath relative to the
>>>currently executing PHP file.
>>
>>include("../some/other/directory/the.www.html");
>>
>>This works as long as as you don't make an include from an included
>>file, as the path is always counted from the first page.
>
>
> Ah! There is the problem.
>
> Just now I noticed that when I check __FILE__ in the PHP code in question
> it does not return the current file but returns one of the includees.
>
> Is there anyway to get the name and directory of the currently executing
> file regardless of whether or not it has been included in another?
> Because if you have multiple files including currentfile.php, you're
> going to need to tweak your include() statement for each one unless there
> is some way to work around that.
>
> Thank you for the information!
>
>
>>if you have the file index.php that includes the page
>>includes/another.php, which in it's turn want to include
>>yetanother.html, you still have to include it as if you did the
>>include from index.php
>>
>>include in index.php:
>>include('includes/another.php');
>>
>>include in another.php:
>>include('includes/yetanother.html');
>>
>>
>> //Aho
>>
>
>

On Apache:

include ($_SERVER['DOCUMENT_ROOT']) . "/relative/to/root/directory.html"

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[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

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