From: Jim Lucas on
Tanel Tammik wrote:
> "Jim Lucas" <lists(a)cmsws.com> wrote in message
> news:4C0E99D9.20809(a)cmsws.com...
>> Tanel Tammik wrote:
>>> Hi,
>>>
>>> i like to find the web root where the current file is. is there a better
>>> solution? it must work both on linux and windows machines...
>>>
>>> <?php
>>> $root = explode('/', $_SERVER['DOCUMENT_ROOT']);
>>> $cwd = explode(DIRECTORY_SEPARATOR, __DIR__);
>>> $web_root = '/' . implode('/', array_diff($cwd, $root));
>>> echo $web_root;
>>> ?>
>>>
>>> maybe there is a function for that :D:D:D
>>>
>>> Br
>>> Tanel
>>>
>>>
>>>
>> If I understand what you are asking for, I think this will work.
>>
>> <?php
>>
>> $web_root = basename($_SERVER['QUERY_STRING']);
>>
>> ?>
>>
>> --
>> Jim Lucas
>>
>> A: Maybe because some people are too annoyed by top-posting.
>> Q: Why do I not get an answer to my question(s)?
>> A: Because it messes up the order in which people normally read text.
>> Q: Why is top-posting such a bad thing?
>
> var_dump($_SERVER['QUERY_STRING']); //outputs: string(0) ""
>
> Br
> Tanel
>
>
>

WOW, totally backwards on that one

try this

<?php

var_dump( dirname( $_SERVER['PHP_SELF'] ) );

?>


--
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
From: Jim Lucas on
Jim Lucas wrote:
> Tanel Tammik wrote:
>> "Jim Lucas" <lists(a)cmsws.com> wrote in message
>> news:4C0E99D9.20809(a)cmsws.com...
>>> Tanel Tammik wrote:
>>>> Hi,
>>>>
>>>> i like to find the web root where the current file is. is there a better
>>>> solution? it must work both on linux and windows machines...
>>>>
>>>> <?php
>>>> $root = explode('/', $_SERVER['DOCUMENT_ROOT']);
>>>> $cwd = explode(DIRECTORY_SEPARATOR, __DIR__);
>>>> $web_root = '/' . implode('/', array_diff($cwd, $root));
>>>> echo $web_root;
>>>> ?>
>>>>
>>>> maybe there is a function for that :D:D:D
>>>>
>>>> Br
>>>> Tanel
>>>>
>>>>
>>>>
>>> If I understand what you are asking for, I think this will work.
>>>
>>> <?php
>>>
>>> $web_root = basename($_SERVER['QUERY_STRING']);
>>>
>>> ?>
>>>
>>> --
>>> Jim Lucas
>>>
>>> A: Maybe because some people are too annoyed by top-posting.
>>> Q: Why do I not get an answer to my question(s)?
>>> A: Because it messes up the order in which people normally read text.
>>> Q: Why is top-posting such a bad thing?
>> var_dump($_SERVER['QUERY_STRING']); //outputs: string(0) ""
>>
>> Br
>> Tanel
>>
>>
>>
>
> WOW, totally backwards on that one
>
> try this
>
> <?php
>
> var_dump( dirname( $_SERVER['PHP_SELF'] ) );
>
> ?>
>
>

Although, after looking a little closer, it has a weird behavior that I didn't
expect.

if you call it from within a file from your DOCUMENT_ROOT it returns the
filename itself. But, if you call it from a file within a subdirectory it gives
you the expected behavior of returning the parent directory structure.

I would have thought it would simply return / if it were in the DOCUMENT_ROOT.

Strange!

--
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
First  |  Prev  | 
Pages: 1 2
Prev: Pagination?
Next: Generic Email