function _mimemail_file in Mime Mail 5
Same name and namespace in other branches
- 6 mimemail.inc \_mimemail_file()
- 7 mimemail.inc \_mimemail_file()
Helper function to extract local files
Parameters
$url a URL to a file:
Return value
an absolute :
3 calls to _mimemail_file()
- mimemail_extract_files in ./
mimemail.inc - Extracts links to local images from html documents.
- mimemail_html_body in ./
mimemail.inc - Generate a multipart message body with a text alternative for some html text
- _mimemail_replace_files in ./
mimemail.inc - Callback for preg_replace_callback()
File
- ./
mimemail.inc, line 116
Code
function _mimemail_file($url = NULL, $name = '', $type = '', $disposition = 'related') {
static $files = array();
if ($url) {
$url = _mimemail_url($url, 'TRUE');
// If the $url is absolute, we're done here.
if (strpos($url, '://') || preg_match('!mailto:!', $url)) {
return $url;
}
else {
// The $url is a relative file path, continue processing.
$file = $url;
}
}
if ($file && file_exists($file)) {
$content_id = md5($file) . '@' . $_SERVER['HTTP_HOST'];
if (!$name) {
$name = substr($file, strrpos($file, '/') + 1);
}
$new_file = array(
'name' => $name,
'file' => $file,
'Content-ID' => $content_id,
'Content-Disposition' => $disposition,
);
$new_file['Content-Type'] = _mimemail_mimetype($file, $type);
$files[] = $new_file;
return 'cid:' . $content_id;
}
$ret = $files;
$files = array();
return $ret;
}