function url_to_realpath in Mail MIME 6
Same name and namespace in other branches
- 8.2 url_to_path.inc \url_to_realpath()
 - 6.2 url_to_path.inc \url_to_realpath()
 - 7.2 url_to_path.inc \url_to_realpath()
 - 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
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 113  - 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('./' . $path);
  }
  return FALSE;
}