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 109
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;
}
doc_Drupal
2016-10-29 09:14:19
Comments
Leave a Comment

Please login to continue.