You are here

function url_to_realpath in Mail MIME 7

Same name and namespace in other branches
  1. 8.2 url_to_path.inc \url_to_realpath()
  2. 6.2 url_to_path.inc \url_to_realpath()
  3. 6 url_to_path.inc \url_to_realpath()
  4. 7.2 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()
MailMIME::attachRegex in ./mailmime.inc
A preg_replace_callback used to attach local files, if possible.

File

./url_to_path.inc, line 122
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(DRUPAL_ROOT . base_path() . $path);
  }
  return FALSE;
}