8.5.x file.inc drupal_realpath($uri)
8.0.x file.inc drupal_realpath($uri)
8.1.x file.inc drupal_realpath($uri)
8.2.x file.inc drupal_realpath($uri)
8.3.x file.inc drupal_realpath($uri)
8.4.x file.inc drupal_realpath($uri)
8.6.x file.inc drupal_realpath($uri)
7.x file.inc 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.


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

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

... See full list


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


ericxb’s picture

Sadly, while the docs report that this call is deprecated they make no mention of what might make a suitable replacement.

file_create_url() seems to fit the bill for today's needs.

ñull’s picture

file_create_url() will return a URL (like the name suggests), not a local file path. Therefore not a replacement.

So what is?

Wolf_22’s picture

Indeed it does, ericxb. Indeed it does!

(Thanks for the heads up on this... Saved me some frustration!)

chales’s picture

I've run into the issue described here on an Acquia DevCloud server, http://us2.php.net/manual/en/function.realpath.php#82770

This thread relates to the issue when trying to import files with the feeds module, http://drupal.org/node/1246418 I will post my fix for feeds in this thread should you have the same issue.

Also adding this debate thread in as a reference for anyone else wondering exactly what to replace this function with, it is a long running topic.

ref: http://drupal.org/node/1201024

glass.dimly’s picture

I'm using file_stream_wrapper_get_instance_by_uri instead of drupal_realpath().

Invoked like so to get the full filesystem path of a uri:

$dir_uri = file_stream_wrapper_get_instance_by_uri('private://');
artur.thiessen’s picture

This is exactly what drupal_realpath() does :D

paulsheldrake’s picture

The docs note that it doesn't work with remote URLs. If you're not using this function on something that will be working with remote files then it's fine to use. They're just trying to make the point that it's not going to work in every case.