| Versions | |
|---|---|
| 7 | drupal_realpath($uri) |
Returns the absolute path of a file or directory
PHP's realpath() does not properly support streams, so this function fills that gap. If a stream wrapped URI is provided, it will be passed to the registered wrapper for handling. If the URI does not contain a scheme or the wrapper implementation does not implement realpath, then FALSE will be returned.
$uri A string containing the URI to verify. If this value is omitted, Drupal's public files directory will be used [public://].
The absolute pathname, or FALSE on failure.
http://php.net/manual/en/function.realpath.php
Compatibility: normal paths and stream wrappers.
realpath()
drupal/
<?php
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;
}
?>