function drupal_realpath

drupal_realpath($uri)

Resolves the absolute filepath of a local URI or filepath.

The use of drupal_realpath() is discouraged, because it does not work for remote URIs. Except in rare cases, URIs should not be manually resolved.

Only use this function if you know that the stream wrapper in the URI uses the local file system, and you need to pass an absolute path to a function that is incompatible with stream URIs.

Parameters

string $uri: A stream wrapper URI or a filepath, possibly including one or more symbolic links.

Return value

string|false The absolute local filepath (with no symbolic links), or FALSE on failure.

See also

DrupalStreamWrapperInterface::realpath()

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

Related topics

File

includes/file.inc, line 2307
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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!file.inc/function/drupal_realpath/7.x