function file_stream_wrapper_get_instance_by_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.

Parameters

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

Return value

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 (Drupal\Core\StreamWrapper\PrivateStream).

Related topics

5 calls to file_stream_wrapper_get_instance_by_uri()
drupal_chmod in drupal/core/includes/file.inc
Sets the permissions on a file or directory.
drupal_realpath in drupal/core/includes/file.inc
Returns the absolute local filesystem path of a stream URI.
file_create_url in drupal/core/includes/file.inc
Creates a web-accessible URL for a stream to an external or local file.
file_get_mimetype in drupal/core/includes/file.inc
Determines an Internet Media Type or MIME type from a filename.
StreamWrapperTest::testUriFunctions in drupal/core/modules/system/lib/Drupal/system/Tests/File/StreamWrapperTest.php
Test the URI and target functions.

File

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

Code

function file_stream_wrapper_get_instance_by_uri($uri) {
  $scheme = file_uri_scheme($uri);
  $class = file_stream_wrapper_get_class($scheme);
  if (class_exists($class)) {
    $instance = new $class();
    $instance
      ->setUri($uri);
    return $instance;
  }
  else {
    return FALSE;
  }
}