As of PHP 5.3.0, you can use __DIR__ as a replacement for dirname(__FILE__)(PHP 4, PHP 5, PHP 7, PHP 8)
dirname — Liefert den Pfad des übergeordneten Verzeichnisses
   Aus einer übergebenen Zeichenkette, die den Pfad zu einer Datei oder einem
   Verzeichnis enthält, gibt diese Funktion den Pfad des Verzeichnisses zurück,
   welches levels Ebenen über dem angegebenen liegt.
  
Hinweis:
dirname() arbeitet nur mit der Eingabezeichenkette und beachtet nicht das eigentliche Dateisystem oder Pfadbestandteile wie etwa "
..".
    Unter Windows geht dirname() von der aktuell
    eingestellten Codepage aus. Damit diese Funktion also bei Pfaden mit
    Mehrbytezeichen den korrekten Verzeichnisnamen erkennt, muss die passende
    Codepage gesetzt sein. Wenn path Zeichen enthält,
    die für die aktuelle Codepage ungültig sind, ist das Verhalten von
    dirname() undefiniert.
   
    Auf anderen Systemen nimmt dirname() an, dass
    path in einer ASCII-kompatiblen Kodierung vorliegen
    muss. Andernfalls ist das Verhalten der Funktion undefiniert.
   
pathEin Pfad.
       Unter Windows wird sowohl der Slash (/) als
       auch der Backslash (\) als Trennzeichen bei
       Pfadangaben benutzt. Unter anderen Betriebssystemen hingegen nur
       der Slash (/).
      
levelsDie Anzahl an übergeordneten Verzeichnissen, die aufgestiegen werden soll.
Dies muss eine ganze Zahl größer 0 sein.
   Gibt den Pfad eines übergeordneten Verzeichnisses zurück. Sind keine
   Pfadtrenner in path, wird ein Punkt
   ('.') zurückgegeben, der das aktuelle Verzeichnis
   angibt. Ansonsten ist die zurückgegebene Zeichenkette der
   path, von dem die abschließendene
   /komponente entfernt wurde.
  
Vorsicht ist geboten, wenn diese Funktion in einer Schleife verwendet wird, die die oberste Verzeichnis-Ebene erreichen kann, da dies zu einer Endlosschleife führen kann.
<?php
dirname('.');    // Ergibt '.'.
dirname('/');    // Ergibt '/' unter Windows und '/' auf *nix-Systemen.
dirname('\\');   // Ergibt `\` unter Windows und '.' auf *nix-Systemen.
dirname('C:\\'); // Ergibt 'C:\' unter Windows und '.' auf *nix-Systemen.
?>
Beispiel #1 dirname()-Beispiel
<?php
echo dirname("/etc/passwd") . PHP_EOL;
echo dirname("/etc/") . PHP_EOL;
echo dirname(".") . PHP_EOL;
echo dirname("C:\\") . PHP_EOL;
echo dirname("/usr/local/lib", 2);Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
/etc / (oder \ unter Windows) . C:\ /usr
As of PHP 5.3.0, you can use __DIR__ as a replacement for dirname(__FILE__)Since the paths in the examples given only have two parts (e.g. "/etc/passwd") it is not obvious whether dirname returns the single path element of the parent directory or whether it returns the whole path up to and including the parent directory.  From experimentation it appears to be the latter.
e.g. 
dirname('/usr/local/magic/bin');
returns '/usr/local/magic'  and not just 'magic'
Also it is not immediately obvious that dirname effectively returns the parent directory of the last item of the path regardless of whether the last item is a directory or a file.  (i.e. one might think that if the path given was a directory then dirname would return the entire original path since that is a directory name.)
Further the presense of a directory separator at the end of the path does not necessarily indicate that last item of the path is a directory, and so 
dirname('/usr/local/magic/bin/');  #note final '/'
would return the same result as in my example above.
In short this seems to be more of a string manipulation function that strips off the last non-null file or directory element off of a path string.To get the directory of current included file:
<?php
dirname(__FILE__);
?>
For example, if a script called 'database.init.php' which is included from anywhere on the filesystem wants to include the script 'database.class.php', which lays in the same directory, you can use:
<?php
include_once(dirname(__FILE__) . '/database.class.php');
?>Be aware that if you call dirname(__FILE__) on Windows, you may get backslashes. If you then try to use str_replace() or preg_replace() to replace part of the path using forward slashes in your search pattern, there will be no match. You can normalize paths with $path = str_replace('\\',  '/' ,$path) before doing any transformationsThe dirname function does not usually return a slash on the end, which might encourage you to create links using code like this:
$url = dirname($_SERVER['PHP_SELF']) . '/somepage.php';
However dirname returns a slash if the path you specify is the root, so $url in that case would become '//somepage.php'.  If you put that URL as the action on a form, for example, submitting the form will try to go to http://somepage.php.
I ran into this when I wrote a site on a url with a path, www.somehost.com/client/somepage.php, where the code above works great, but then wanted to put it on a subdomain, client.somehost.com/somepage.php, where things started breaking.
The best solution would be to create a function that generates absolute URLs and use that throughout the site, but creating a safe_dirname function (and an htaccess rewrite to fix double-slashes just in case) fixed the issue for me:
<?php
function safe_dirname($path)
{
   $dirname = dirname($path);
   return $dirname == '/' ? '' : $dirname;
}
?>Attention with this. Dirname likes to mess with the slashes.
On Windows, Apache: 
<?php
echo '$_SERVER[PHP_SELF]: ' . $_SERVER['PHP_SELF'] . '<br />';
echo 'Dirname($_SERVER[PHP_SELF]: ' . dirname($_SERVER['PHP_SELF']) . '<br>';
?>
prints out
$_SERVER[PHP_SELF]: /index.php
Dirname($_SERVER[PHP_SELF]: \