protected function LocalStream::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|bool If $uri is not set, returns the canonical absolute path of the URI previously set by the Drupal\Core\StreamWrapper\StreamWrapperInterface::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.

10 calls to LocalStream::getLocalPath()
LocalReadOnlyStream::stream_open in drupal/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php
Support for fopen(), file_get_contents(), etc.
LocalStream::chmod in drupal/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::chmod().
LocalStream::dir_opendir in drupal/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
Support for opendir().
LocalStream::mkdir in drupal/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
Support for mkdir().
LocalStream::realpath in drupal/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::realpath().

... See full list

File

drupal/core/lib/Drupal/Core/StreamWrapper/LocalStream.php, line 161
Definition of Drupal\Core\StreamWrapper\LocalStream.

Class

LocalStream
Defines a Drupal stream wrapper base class for local files.

Namespace

Drupal\Core\StreamWrapper

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;
}