Skip navigation
Help

file_stream_wrapper_get_instance_by_scheme

7 file.inc file_stream_wrapper_get_instance_by_scheme($scheme)

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

This helper method returns a stream instance using a scheme. That is, the passed string does not contain a "://". For example, "public" is a scheme but "public://" is a URI (stream). This is because the later contains both a scheme and target despite target being empty.

Note: the instance URI will be initialized to "scheme://" so that you can make the customary method calls as if you had retrieved an instance by URI.

Parameters

$scheme: If the stream was "public://target", "public" would be the scheme.

Return value

Returns a new stream wrapper object appropriate for the given $scheme. For example, for the public scheme a stream wrapper object (DrupalPublicStreamWrapper). FALSE is returned if no registered handler could be found.

Related topics

12 calls to file_stream_wrapper_get_instance_by_scheme()

File

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

Code

function file_stream_wrapper_get_instance_by_scheme($scheme) {
  $class = file_stream_wrapper_get_class($scheme);
  if (class_exists($class)) {
    $instance = new $class();
    $instance->setUri($scheme . '://');
    return $instance;
  }
  else {
    return FALSE;
  }
}