function drupal_realpath

Returns the absolute local filesystem path of a stream URI.

This function was originally written to ease the conversion of 6.x code to use 7.x stream wrappers. However, it assumes that every URI may be resolved to an absolute local filesystem path, and this assumption fails when stream wrappers are used to support remote file storage. Remote stream wrappers may implement the realpath method by always returning FALSE. The use of drupal_realpath() is discouraged, and is slowly being removed from core functions where possible.

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.

@todo This function is deprecated, and should be removed wherever possible.

Parameters

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

Return value

The absolute local filesystem path (with no symbolic links), or FALSE on failure.

See also

Drupal\Core\StreamWrapper\StreamWrapperInterface::realpath()

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

Related topics

42 calls to drupal_realpath()
archiver_get_archiver in drupal/core/includes/common.inc
Creates the appropriate archiver for the specified file.
ColorTest::_testColor in drupal/core/modules/color/lib/Drupal/color/Tests/ColorTest.php
Tests the Color module functionality using the given theme.
CommentPreviewTest::testCommentPreview in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php
Tests comment preview.
drupal_move_uploaded_file in drupal/core/includes/file.inc
Moves an uploaded file to a new location.
FileFieldTestBase::replaceNodeFile in drupal/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
Replaces a file within a node.

... See full list

File

drupal/core/includes/file.inc, line 1638
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();
  }
  return realpath($uri);
}