W3cubDocs

/Drupal 8

protected function LocalStream::getTarget

protected LocalStream::getTarget($uri = NULL)

Returns the local writable target of the resource within the stream.

This function should be used in place of calls to realpath() or similar functions when attempting to determine the location of a file. While functions like realpath() may return the location of a read-only file, this method may return a URI or path suitable for writing that is completely separate from the URI used for reading.

Parameters

string $uri: Optional URI.

Return value

string|bool Returns a string representing a location suitable for writing of a file, or FALSE if unable to write to the file such as with read-only streams.

File

core/lib/Drupal/Core/StreamWrapper/LocalStream.php, line 87

Class

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

Namespace

Drupal\Core\StreamWrapper

Code

protected function getTarget($uri = NULL) {
  if (!isset($uri)) {
    $uri = $this->uri;
  }

  list(, $target) = explode('://', $uri, 2);

  // Remove erroneous leading or trailing, forward-slashes and backslashes.
  return trim($target, '\/');
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!StreamWrapper!LocalStream.php/function/LocalStream::getTarget/8.1.x