function DrupalLocalStreamWrapper::getLocalPath

Returns the canonical absolute path of the URI, if possible.

Parameters

string $uri: (optional) The stream wrapper URI to be converted to a canonical absolute path. This may point to a directory or another type of file.

Return value

string|false If $uri is not set, returns the canonical absolute path of the URI previously set by the DrupalStreamWrapperInterface::setUri() function. If $uri is set and valid for this class, returns its canonical absolute path, as determined by the realpath() function. If $uri is set but not valid, returns FALSE.

11 calls to DrupalLocalStreamWrapper::getLocalPath()
DrupalLocalStreamWrapper::chmod in includes/stream_wrappers.inc
Base implementation of chmod().
DrupalLocalStreamWrapper::dir_opendir in includes/stream_wrappers.inc
Support for opendir().
DrupalLocalStreamWrapper::mkdir in includes/stream_wrappers.inc
Support for mkdir().
DrupalLocalStreamWrapper::realpath in includes/stream_wrappers.inc
Base implementation of realpath().
DrupalLocalStreamWrapper::rename in includes/stream_wrappers.inc
Support for rename().

... See full list

1 method overrides DrupalLocalStreamWrapper::getLocalPath()
DrupalPublicStreamWrapper::getLocalPath in includes/stream_wrappers.inc
Returns the canonical absolute path of the URI, if possible.

File

includes/stream_wrappers.inc, line 371

Class

DrupalLocalStreamWrapper
Drupal stream wrapper base class for local files.

Code

protected function getLocalPath($uri = NULL) {
    if (!isset($uri)) {
        $uri = $this->uri;
    }
    $path = $this->getDirectoryPath() . '/' . $this->getTarget($uri);
    $realpath = realpath($path);
    if (!$realpath) {
        // This file does not yet exist.
        $realpath = realpath(dirname($path)) . '/' . drupal_basename($path);
    }
    $directory = realpath($this->getDirectoryPath());
    if (!$realpath || !$directory || strpos($realpath, $directory) !== 0) {
        return FALSE;
    }
    return $realpath;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.