Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function drupal_dirname

Same name and namespace in other branches
  1. 8.9.x core/includes/file.inc \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.

Parameters

$uri: A URI or path.

Return value

A string containing the directory name.

See also

dirname()

http://drupal.org/node/515192

Related topics

PHP wrapper functions
Functions that are wrappers or custom implementations of PHP functions.
File interface
Common file handling functions.
5 calls to drupal_dirname()
FileTokenReplaceTestCase::testFileTokenReplacement in modules/file/tests/file.test
Creates a file, then tests the tokens generated from it.
FileUnmanagedCopyTest::testOverwriteSelf in modules/simpletest/tests/file.test
Copy a file onto itself.
file_destination in includes/file.inc
Determines the destination path for a file.
file_unmanaged_copy in includes/file.inc
Copies a file to a new location without invoking the file API.
image_style_create_derivative in modules/image/image.module
Creates a new image derivative based on an image style.

File

includes/file.inc, line 2456

Code

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)->dirname ($uri);
 }
 else {
 return dirname ($uri);
 }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.