Posted by MBS on 11/16/05 14:51
"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
>
[Back to original message]
|