function drupal_dirname

Gets the name of the directory from a given path.

PHP's dirname() does not properly pass streams, so this function fills that gap. It is backwards compatible with normal paths and will use PHP's dirname() as a fallback.

Compatibility: normal paths and stream wrappers.


$uri: A URI or path.

Return value

A string containing the directory name.

See also


Related topics

5 calls to drupal_dirname()
FileTokenReplaceTestCase::testFileTokenReplacement in drupal/modules/file/tests/file.test
Creates a file, then tests the tokens generated from it.
FileUnmanagedCopyTest::testOverwriteSelf in drupal/modules/simpletest/tests/file.test
Copy a file onto itself.
file_destination in drupal/includes/
Determines the destination path for a file.
file_unmanaged_copy in drupal/includes/
Copies a file to a new location without invoking the file API.
image_style_create_derivative in drupal/modules/image/image.module
Creates a new image derivative based on an image style.


drupal/includes/, line 2369
API for handling file uploads and server file management.


function drupal_dirname($uri) {
  $scheme = file_uri_scheme($uri);
  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
    return file_stream_wrapper_get_instance_by_scheme($scheme)
  else {
    return dirname($uri);