You are here

function _cdn_file_path_resolve_relative_paths in CDN 5

Helper function to resolve relative file paths.

I got the regular expression for this from: http://www.troubleshooters.com/codecorn/littperl/perlreg.htm and adapted it to work with PHP.

Parameters

file_path: A file path that possibly contains relative references (double dot).

Return value

The same file path, but with the relative references resolved.

File

./cdn.inc, line 229
Basic functions for CDN integration and synchronization.

Code

function _cdn_file_path_resolve_relative_paths($file_path) {

  // Prepend a leading slash, this allows for a simpler regexp.
  $file_path = "/" . $file_path;

  // Regular expression
  while (preg_match('/\\.\\./', $file_path)) {
    $file_path = preg_replace('/\\/[^\\/]*\\/\\.\\./', '', $file_path);
  }

  // Remove the leading slash again.
  $file_path = substr($file_path, 1);
  return $file_path;
}