php Function Dirname - Using Absolute Paths in PHP
The php function dirname is an inbuilt utility that gets the parent directory path of a file or directory path. It will return the string that contains the path including a dot ('.') if there are no slashes in the path, indicating the current directory. The function is very useful when dealing with absolute paths, as some scripts require them to work properly on the server.
Using absolute paths in PHP can be a bit tricky. Since PHP can be used on a variety of different operating systems, there are sometimes differences in how things like the path separator or drive letters are handled. This can result in an unexpected or incorrect value being returned from a function that uses an absolute path.
A way to avoid these issues is to use an inbuilt function called dirname(). This function takes a path string and returns the path of the parent directory that is a number of levels up from the current directory. The only parameter required for this function is the path string. The number of levels to go up can be set using the optional second argument.
In PHP 4.0.3 dirname() was fixed to be POSIX-compliant. This means that it operates naively on the input string and is not aware of the actual filesystem or path components such as '..'.