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  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2007-05-05 15:05 UTC
Package:
Bug Type:
Summary:
From: richard at hyperlink dot net dot nz
New email:
PHP Version: Package Version: OS:

 

 [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] cipri (Cipriano Groenendal)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. I moved the basename to a location after the CID translation phase, so that foldernames are now taken into consideration during translation.
 [2007-05-05 15:05 UTC] cipri (Cipriano Groenendal)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/Mail_Mime Fixed in 1.4.0