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.

Parameters

$uri: A URI or path.

Return value

A string containing the directory name.

See also

dirname()

http://drupal.org/node/515192

Related topics

6 calls to drupal_dirname()
FileTokenReplaceTest::testFileTokenReplacement in drupal/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php
Creates a file, then tests the tokens generated from it.
file_destination in drupal/core/includes/file.inc
Determines the destination path for a file.
file_unmanaged_copy in drupal/core/includes/file.inc
Copies a file to a new location without invoking the file API.
image_style_create_derivative in drupal/core/modules/image/image.module
Creates a new image derivative based on an image style.
locale_translation_source_build in drupal/core/modules/locale/locale.translation.inc
Builds abstract translation source.

... See full list

File

drupal/core/includes/file.inc, line 1669
API for handling file uploads and server file management.

Code

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