function file_stream_wrapper_get_instance_by_uri

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.

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 (DrupalPrivateStreamWrapper).

Related topics

File

includes/file.inc, line 303
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;
  }
}

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