Re: Full versus relative URLs

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

 



-----------------------------------------------------------------------
Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get
a Free CD of Ubuntu mailed to your door without any cost. Visit :
www.ubuntu.com
----------------------------------------------------------------------


On Wed, Feb 18, 2009 at 11:05 PM, PJ <af.gourmet@xxxxxxxxxxxx> wrote:

> Stuart wrote:
> > 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
>

dirname
(PHP 4, PHP 5)
dirname — Returns directory name component of path
Description
string dirname ( string $path )
Given a string containing a path to a file, this function will return the
name of the directory.
Parameters
path
A path.
On Windows, both slash (/) and backslash (\) are used as directory separator
character. In other environments, it is the forward slash (/).
Return Values
Returns the name of the directory. If there are no slashes in path , a dot
('.') is returned, indicating the current directory. Otherwise, the returned
string is path with any trailing /component removed.
Changelog
Version
Description
5.0.0
dirname() is now binary safe
4.0.3
dirname() was fixed to be POSIX-compliant.
Examples
Example #1 dirname() example
<?php
$path = "/etc/passwd";
$file = dirname($path); // $file is set to "/etc"
?>
Notes
Note: Since PHP 4.3.0, you will often get a slash or a dot back from
dirname() in situations where the older functionality would have given you
the empty string.
Check the following change example:
<?php
//before PHP 4.3.0
dirname('c:/'); // returned '.'
//after PHP 4.3.0
dirname('c:/x'); // returns 'c:\'
dirname('c:/Temp/x'); // returns 'c:/Temp'
dirname('/x'); // returns '\'
?>

>
> >
> >
> >> 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 . before the quotemark  is the concatenation operator which joins the
string(texts) together. :)



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