Re: Full versus relative URLs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul M Foster wrote:
> On Wed, Feb 18, 2009 at 12:05:21PM -0500, PJ wrote:
>
>> Stuart wrote:
>>> 2009/2/18 PJ <af.gourmet@xxxxxxxxxxxx>:
>>>
>>>> Stuart wrote:
>>>>
>>>>>>> <?php include dirname(__FILE__)."/../header.php"; ?>
>>>>>>>
>
> <snip>
>
>>>
>> What confused me here is that often, in examples, there are all sorts of
>> references to files and there seems to be no standard as to how to refer
>> to them in non-scripts such as these e-mails. So, I thought that
>> dirname(_FILE_) was a general reference to a directory name and a
>> file... :-(
>> I don't want to defend myself here, but I cannot be expected to know all
>> functions and look up anything that might resemble a function...
>> I still do not understand, and that is the keyword here, I am trying to
>> understand things - what does /../header.php mean. I know the 2 dots
>> mean a higher directory in Unix... but I understood that ../ would mean
>> the root directory - so what is the / before the ../header.php mean?
>> When including scripts or pages, i find that if I am referencing to the
>> current directory, just the filename or /filename works. If the
>> reference is up a level, ../ works
>>
>> e.g. to reference root/images/ from root/authors = ../images/file.ext
>> from root = /images/file.ext or images/file.ext
>>
>> I haven't needed to go to a deeper level yet.
>
> Let's break it down: dirname(__FILE__) . "/../header.php";
>
> __FILE__ is a constant that represents the filename of whatever file
> it's in. This filename includes the directory to the file.
>
> dirname() parses out just the directory for the filename passed as a
> parameter.
>
> The "." is, of course, the "concatenate" parameter for PHP. So we're
> going to add on whatever comes after the directory for the file.
>
> "/../header.php"
>
> This one is a little trickier. We want a file called header.php, but
> it's in a directory just above where you are. In Unix/Linux (and
> therefore most internet servers), "../header.php" represents a file
> called header.php in the directory just above where you are. Now, you'll
> notice that what's quoted is "/../header.php", not "../header.php".
> There's a leading slash there. Why? That's because we're going to append
> it to a directory which has no leading slash. So if dirname(__FILE__)
> yields "/var/www/includes", and you just add "../header.php" to it,
> you'd get: /var/www/includes../header.php, not the file you want. The
> file you want is: /var/www/includes/../header.php. And in this case,
> header.php actually resides in /var/www (one directory up from
> /var/www/includes).
>
> Paul
OK, great explanation... it's what I had been hoping for ... you're a
great "educator"
Thanks...
In my case though, changing from

Original: include ("lib/header1.php");
to: include dirname(_FILE_)."/lib/header1.php";
works, but what have I gained?


-- 

Phil Jourdan --- pj@xxxxxxxxxxxxx
http://www.ptahhotep.com
http://www.chiccantine.com

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux