7 file.inc | drupal_realpath($uri) |
8 file.inc | 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.
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
DrupalStreamWrapperInterface::realpath()
http://php.net/manual/function.realpath.php
Related topics
- 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.
File
- includes/
file.inc, line 2230 - 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;
}
Comments
Deprecation replacement
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.drupal_realpath errors
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
What and how to use instead???
Dear Sirs
I am not good in using abstract classes and interfaces in PHP
So if this function is depricated, what should I use instead?
And how to?
I've read much about Straem Wrappers but still have no idea what exact it is.
Could you answer me with links on real code wich shows the ways to define realpath by uri using Drupal core functions which are not supposed to be deprived?
Thanks in advance