Skip navigation
Help

drupal_realpath

7 file.inc drupal_realpath($uri)

Returns the absolute path of a file or directory

PHP's realpath() does not properly support streams, so this function fills that gap. If a stream wrapped URI is provided, it will be passed to the registered wrapper for handling. If the URI does not contain a scheme or the wrapper implementation does not implement realpath, then FALSE will be returned.

Compatibility: normal paths and stream wrappers.

Parameters

$uri: A string containing the URI to verify.

Return value

The absolute pathname, or FALSE on failure.

See also

http://php.net/manual/en/function.realpath.php

http://drupal.org/node/515192

realpath()

Related topics

36 calls to drupal_realpath()

File

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

Code

function drupal_realpath($uri) {
  // If this URI is a stream, pass it off to the appropriate stream wrapper.
  // Otherwise, attempt PHP's realpath. This allows use of drupal_realpath even
  // for unmanaged files outside of the stream wrapper interface.
  if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {
    return $wrapper->realpath();
  }
  // Check that the uri has a value. There is a bug in PHP 5.2 on *BSD systems
  // that makes realpath not return FALSE as expected when passing an empty
  // variable.
  // @todo Remove when Drupal drops support for PHP 5.2.
  elseif (!empty($uri)) {
    return realpath($uri);
  }
  return FALSE;
}