drupal_dirname

Versions
7
drupal_dirname($uri)

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.

See also

http://drupal.org/node/515192

See also

dirname()

Parameters

$uri A URI or path.

Return value

A string containing the directory name.

Related topics

▾ 3 functions call drupal_dirname()

file_destination in includes/file.inc
Determines the destination path for a file depending on how replacement of existing files should be handled.
file_unmanaged_copy in includes/file.inc
Copy a file to a new location without calling any hooks or making any changes to the database.
image_style_create_derivative in modules/image/image.module
Create a new image based on an image style.

Code

includes/file.inc, line 1824

<?php
function drupal_dirname($uri) {
	$scheme = file_uri_scheme($uri);

  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
    $target  = file_uri_target($uri);
    $dirname = dirname($target);

    if ($dirname == '.') {
      $dirname = '';
    }

    return $scheme . '://' . $dirname;
  }
  else {
    return dirname($uri);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.