W3cubDocs

/Drupal 8

function file_uri_target

file_uri_target($uri)

Returns the part of a URI after the schema.

Parameters

string $uri: A stream, referenced as "scheme://target" or "data:target".

Return value

string|bool A string containing the target (path), or FALSE if none. For example, the URI "public://sample/test.txt" would return "sample/test.txt".

See also

file_uri_scheme()

Related topics

File interface
Common file handling functions.

File

core/includes/file.inc, line 107
API for handling file uploads and server file management.

Code

function file_uri_target($uri) {
  // Remove the scheme from the URI and remove erroneous leading or trailing,
  // forward-slashes and backslashes.
  $target = trim(preg_replace('/^[\w\-]+:\/\/|^data:/', '', $uri), '\/');

  // If nothing was replaced, the URI doesn't have a valid scheme.
  return $target !== $uri ? $target : FALSE;
}

© 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!includes!file.inc/function/file_uri_target/8.1.x