Re: Full versus relative URLs

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

 



2009/2/18 PJ <af.gourmet@xxxxxxxxxxxx>:
> Stuart wrote:
>>>> <?php include dirname(__FILE__)."/../header.php"; ?>
> This generates a Fatal error: Cal to undefined function dirname() .... ????

The dirname function is present in both PHP 4 and 5 and does not rely
on any external libraries. Are you sure you're spelling it right?

http://php.net/dirname

> I must be really dense...
> What I don't understand in the above is this - dirname refers to what
> directory? -- the directory of the file that is including? what if the
> directory is the root directory of the site?
>
> (_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
> this, the file which is including the file header.php?

The __FILE__ (note 2 _'s either side) constant is the full path and
filename to the current script. The dirname function knocks the
filename off it to give you the directory the current script is in.
You can then append a / and then the relative path to the script you
want to include. By doing this you're ensuring that all includes are
relative to the current script and are not affected by ini settings or
anything else.

> and what does the . mean and then "/../header.php" --- I don't
> understand what to enter here

The . is the string append operator. I tend to assume the most basic
level of PHP knowledge from users of this list and I include the
string append operator in that set. You might want to find a beginners
tutorial for PHP and work through that to give you a solid foundation
before attempting to work with multiple scripts.

-Stuart

-- 
http://stut.net/

-- 
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