You are here

function url_to_realpath in Emogrifier 6

Same name and namespace in other branches
  1. 8 url_to_path.inc \url_to_realpath()
  2. 7 url_to_path.inc \url_to_realpath()

Returns an absolute local path corresponding to a given URL, if possible.

For example, when looking for image URLs within an email message body for possible conversion to inline attachments, the following code might be used:


  if ( !url_is_external($url)
    && ($path = url_to_realpath($url))
    && file_exists($path) ) {
    // Attach $path and replace $url.
    ...
  }

Parameters

$url: The internal path or external URL being linked to, such as "node/34" or "http://example.com/drupal/foo".

Return value

FALSE if $url contains a host/port/path that does not match the current site, or else an absolute local path such as "/path/to/drupal/node/34".

See also

url_to_path()

1 call to url_to_realpath()
_emogrifier_process in ./emogrifier.module
Returns $text with stylesheet rules converted to inline style attributes.

File

./url_to_path.inc, line 114
Provide a url_to_path() function by refactoring and repurposing conf_path().

Code

function url_to_realpath($url) {
  $path = url_to_path($url);
  if ($path) {
    return realpath(getcwd() . '/' . $path);
  }
  return FALSE;
}