1 file.inc file_stream_wrapper_get_instance_by_uri($uri)

Returns a reference to the stream wrapper class responsible for a given URI.

The scheme determines the stream wrapper class that should be used by consulting the stream wrapper registry.


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

Return value

BackdropStreamWrapperInterface: Returns a new stream wrapper object appropriate for the given URI or FALSE if no registered handler could be found. For example, a URI of "private://example.txt" would return a new private stream wrapper object (BackdropPrivateStreamWrapper).

Related topics


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


function file_stream_wrapper_get_instance_by_uri($uri) {
  $scheme = file_uri_scheme($uri);
  if (!$scheme || !file_stream_wrapper_valid_scheme($scheme)) {
    return FALSE;

  $class = file_stream_wrapper_get_class($scheme);
  if (class_exists($class)) {
    /* @var BackdropStreamWrapperInterface $instance */
    $instance = new $class();
    return $instance;
  else {
    return FALSE;