Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.12

Request #4504 addHTMLImage does not work in cases when filename contains a path
Submitted: 2005-06-01 22:48 UTC
From: richard at hyperlink dot net dot nz Assigned: cipri
Status: Closed Package: Mail_Mime
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: 1.4.0, 1.4.0a1    
Subscription  


 [2005-06-01 22:48 UTC] richard at hyperlink dot net dot nz
Description: ------------ When called with a single argument, specifying the filename of the image, addHTMLImage does not work correctly if the image in the HTML is specified with a path. E.g. when the HTML contains "<img src=images/mars.jpg>" and addHTMLImage("images/mars.jpg") is called, the image will not be inserted correctly. This is because the function addHTMLImage truncates the filename to basename($file), and it is this truncated $file that is then later used when replacing the filename with the attachment CID (excuse me if my terminalogy is not correct). I was going to suggest an alternate implementation, however this would probably break a lot of existing code. So more explicit documentation of what cases addHTMLImage is probably a better solution. Since addHTMLImage also truncates the $name parameter, supplying the actual file contents in $file and the name in $name would still be problematic for my need, so I added the following function to the Mail_mime class. This function will find all images in img tags and load all the files into the Mime_mail object. It takes a parameter $path which is prepended to the filenames, for when the files are not relative to the current working directory. You need to call addHTMLBody first. Note the regular expression only matches IMG tags where the SRC attribute is inside double quotes. function findAddHTMLImages($path='') { preg_match_all('|<img .*src="(.+)".*>|Ui', $this->_htmlbody, $image_matches, PREG_PATTERN_ORDER); $html_images=array_unique($image_matches[1]); foreach ($html_images as $filename) { $filedata=$this->_file2str($path.$filename); if (PEAR::isError($filedata)) { return $filedata; } $this->_html_images[] = array( 'body' => $filedata, 'name' => $filename, 'c_type' => 'application/octet-stream', 'cid' => md5(uniqid(time()))); } return true; }

Comments

 [2006-04-09 15:56 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2007-05-05 15:05 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!