PHP dirname() Function

The dirname() function returns the directory name from a path.

string dirname ( string $path [, int $levels = 1 ] )

Given a string containing the path of a file or directory, this function will return the parent directory's path that is levels up from the current directory.

Example -

The output of the code above will be:

Example -

ParameterDescription
pathOn Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
levelsThe number of parent directories to go up.This must be an integer greater than 0.