1. drupal
    1. 8
    2. 7
7 – 8 drupal_realpath($uri)

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.


$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



Related topics

▾ 39 functions call drupal_realpath()

archiver_get_archiver in includes/common.inc
Create the appropriate archiver for the specified file.
ColorTestCase::_testColor in modules/color/color.test
Tests color module functionality using the given theme.
DrupalErrorHandlerUnitTest::testErrorHandler in modules/simpletest/tests/error.test
Test the error handler.
DrupalErrorHandlerUnitTest::testExceptionHandler in modules/simpletest/tests/error.test
Test the exception handler.
DrupalWebTestCase::drupalPost in modules/simpletest/drupal_web_test_case.php
Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
drupal_move_uploaded_file in includes/file.inc
Moves an uploaded file to a new location.
FileFieldTestCase::replaceNodeFile in modules/file/tests/file.test
Replace a file within a node.
FileFieldTestCase::uploadNodeFile in modules/file/tests/file.test
Upload a file to a node.
FileFieldWidgetTestCase::testMultiValuedWidget in modules/file/tests/file.test
Tests upload and remove buttons, with and without Ajax, for multiple multi-valued File field.
FileFieldWidgetTestCase::testPrivateFileComment in modules/file/tests/file.test
Tests that download restrictions on private files work on comments.
FileManagedFileElementTestCase::testManagedFile in modules/file/tests/file.test
Tests the managed_file element type.
FileSaveUploadTest::setUp in modules/simpletest/tests/file.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
FileSaveUploadTest::testExistingError in modules/simpletest/tests/file.test
Test for failure when uploading over a file that already exists.
FileSaveUploadTest::testExistingRename in modules/simpletest/tests/file.test
Test renaming when uploading over a file that already exists.
FileSaveUploadTest::testExistingReplace in modules/simpletest/tests/file.test
Test replacement when uploading over a file that already exists.
FileSaveUploadTest::testHandleDangerousFile in modules/simpletest/tests/file.test
Test dangerous file handling.
FileSaveUploadTest::testHandleExtension in modules/simpletest/tests/file.test
Test extension handling.
FileSaveUploadTest::testHandleFileMunge in modules/simpletest/tests/file.test
Test file munge handling.
FileSaveUploadTest::testNormal in modules/simpletest/tests/file.test
Test the file_save_upload() function.
FileTransfer::checkPath in includes/filetransfer/filetransfer.inc
Checks that the path is inside the jail and throws an exception if not.
file_copy in includes/file.inc
Copies a file to a new location and adds a file record to the database.
file_delete in includes/file.inc
Delete a file and its database record.
file_move in includes/file.inc
Move a file to a new location and update the file's database entry.
file_unmanaged_copy in includes/file.inc
Copies a file to a new location without invoking the file API.
FormExampleTestCase::testTutorials in examples/form_example/form_example.test
Test each tutorial
ImageExampleTestCase::testImageExamplePage in examples/image_example/image_example.test
Tests for image block provided by module.
ImageFieldDisplayTestCase::testImageFieldDefaultImage in modules/image/image.test
Test use of a default image with an image field.
ImageFieldTestCase::uploadNodeImage in modules/image/image.test
Upload an image to a node.
image_gd_save in modules/system/image.gd.inc
GD helper to write an image resource to a destination file.
image_style_flush in modules/image/image.module
Flush cached media for a style.
RdfRdfaMarkupTestCase::testAttributesInMarkupFile in modules/rdf/rdf.test
Ensure that file fields have the correct resource as the object in RDFa when displayed as a teaser.
SystemThemeFunctionalTest::testThemeSettings in modules/system/system.test
Test the theme settings form.
system_retrieve_file in modules/system/system.module
Attempts to get a file using drupal_http_request and to store it locally.
update_manager_file_get in modules/update/update.manager.inc
Copies a file from $url to the temporary directory for updates.
update_manager_install_form_submit in modules/update/update.manager.inc
Handle form submission when installing new projects via the update manager.
update_manager_update_ready_form_submit in modules/update/update.manager.inc
Submit handler for the form to confirm that an update should continue.
UserPictureTestCase::saveUserPicture in modules/user/user.test
_color_render_images in modules/color/color.module
Render images that match a given palette.
_system_theme_settings_validate_path in modules/system/system.admin.inc
Helper function for the system_theme_settings form.


includes/file.inc, line 2222

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;