function drupal_realpath

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.


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


Related topics

47 calls to drupal_realpath()
archiver_get_archiver in drupal/includes/
Creates the appropriate archiver for the specified file.
ColorTestCase::_testColor in drupal/modules/color/color.test
Tests the Color module functionality using the given theme.
CommentPreviewTest::testCommentPreview in drupal/modules/comment/comment.test
Test comment preview.
DrupalErrorHandlerTestCase::testErrorHandler in drupal/modules/simpletest/tests/error.test
Test the error handler.
DrupalErrorHandlerTestCase::testExceptionHandler in drupal/modules/simpletest/tests/error.test
Test the exception handler.

... See full list


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


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
  elseif (!empty($uri)) {
    return realpath($uri);
  return FALSE;