8.3.x file.inc file_stream_wrapper_uri_normalize($uri)
8.0.x file.inc file_stream_wrapper_uri_normalize($uri)
8.1.x file.inc file_stream_wrapper_uri_normalize($uri)
8.2.x file.inc file_stream_wrapper_uri_normalize($uri)
8.4.x file.inc file_stream_wrapper_uri_normalize($uri)
7.x file.inc file_stream_wrapper_uri_normalize($uri)

Normalizes a URI by making it syntactically correct.

A stream is referenced as "scheme://target".

The following actions are taken:

  • Remove trailing slashes from target
  • Trim erroneous leading slashes from target. e.g. ":///" becomes "://".


$uri: String reference containing the URI to normalize.

Return value

The normalized URI.

Related topics

6 calls to file_stream_wrapper_uri_normalize()
file_build_uri in includes/file.inc
Constructs a URI to Drupal's default files location given a relative path.
file_create_htaccess in includes/file.inc
Creates a .htaccess file in the given directory.
file_scan_directory in includes/file.inc
Finds all files that match a given mask in a given directory.
file_unmanaged_copy in includes/file.inc
Copies a file to a new location without invoking the file API.
image_style_url in modules/image/image.module
Returns the URL for an image derivative given a style and image path.

... See full list


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


function file_stream_wrapper_uri_normalize($uri) {
  // Inline file_uri_scheme() function call for performance reasons.
  $position = strpos($uri, '://');
  $scheme = $position ? substr($uri, 0, $position) : FALSE;

  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
    $target = file_uri_target($uri);

    if ($target !== FALSE) {
      $uri = $scheme . '://' . $target;
  return $uri;


amagdy’s picture

in the else part, a variable $url is used while $uri should be used

$url = 'file://' . $uri;

should be

$uri = 'file://' . $uri;

TwoD’s picture