file_stream_wrapper_uri_normalize

Versions
7
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 all occurrences of the wrapper's directory path
  • Remove trailing slashes from target
  • Trim erroneous leading slashes from target. e.g. ":///" becomes "://".

Parameters

$uri String reference containing the URI to normalize.

Return value

The normalized URI.

Related topics

▾ 6 functions call file_stream_wrapper_uri_normalize()

file_build_uri in includes/file.inc
Given a relative path, construct a URI into Drupal's default files location.
file_create_htaccess in includes/file.inc
Creates an .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
Copy a file to a new location without calling any hooks or making any changes to the database.
system_update_7035 in modules/system/system.install
Migrate upload module files to the new {file} table.
user_save in modules/user/user.module
Save changes to a user account or add a new user.

Code

includes/file.inc, line 209

<?php
function file_stream_wrapper_uri_normalize($uri) {
  $scheme = file_uri_scheme($uri);

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

    // Remove all occurrences of the wrapper's directory path.
    $directory_path = file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath();
    $target = str_replace($directory_path, '', $target);

    // Trim trailing slashes from target.
    $target = rtrim($target, '/');

    // Trim erroneous leading slashes from target.
    $uri = $scheme . '://' . ltrim($target, '/');
  }
  return $uri;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.