public function testFilenameSetsInConstructor() { $file = new Swift_Message_EmbeddedFile("some string", "foo", "image/jpeg", "my_cid"); $this->assertEqual("foo", $file->getFileName()); $structure = $file->build()->readFull(); $this->assertPattern("~Content-Type: image/jpeg;\\s+name=foo\r\nContent-Transfer-Encoding: base64\r\n" . "Content-Disposition: inline;\\s* filename=foo\r\n" . "Content-ID: <my_cid>\r\n\r\n.*~s", $structure); $file = new Swift_Message_EmbeddedFile(new Swift_File(TestConfiguration::FILES_PATH . "/gecko.png"), "foo.png", "image/jpeg", "my_cid"); $this->assertEqual("foo.png", $file->getFileName()); $structure = $file->build()->readFull(); $this->assertPattern("~Content-Type: image/jpeg;\\s+name=foo\\.png\r\nContent-Transfer-Encoding: base64\r\n" . "Content-Disposition: inline;\\s* filename=foo\\.png\r\n" . "Content-ID: <my_cid>\r\n\r\n.*~s", $structure); }
/** * Set data for the image * This overrides setData() in Swift_Message_Attachment * @param Swift_File The data to set, as a file * @throws Swift_Message_MimeException If the image cannot be used, or the file is not */ public function setData($data, $read_filename = true) { if (!$data instanceof Swift_File) { throw new Exception("Parameter 1 of " . __METHOD__ . " must be instance of Swift_File"); } parent::setData($data, $read_filename); $img_data = @getimagesize($data->getPath()); if (!$img_data) { throw new Swift_Message_MimeException("Cannot use file '" . $data->getPath() . "' as image since getimagesize() was unable to detect a file format. " . "Try using Swift_Message_EmbeddedFile instead"); } $type = image_type_to_mime_type($img_data[2]); $this->setContentType($type); if (!$this->getFileName()) { $this->setFileName($data->getFileName()); } }
/** * Set data for the image * This overrides setData() in Swift_Message_Attachment * @param Swift_File The data to set, as a file * @throws Swift_Message_MimeException If the image cannot be used, or the file is not */ function setData(&$data, $read_filename = true) { if (!is_a($data, "Swift_File")) { trigger_error("Parameter 1 of " . __CLASS__ . "::" . __FUNCTION__ . " must be instance of Swift_File"); return; } parent::setData($data, $read_filename); $img_data = @getimagesize($data->getPath()); if (!$img_data) { Swift_Errors::trigger(new Swift_Message_MimeException("Cannot use file '" . $data->getPath() . "' as image since getimagesize() was unable to detect a file format. " . "Try using Swift_Message_EmbeddedFile instead")); return; } $type = image_type_to_mime_type($img_data[2]); $this->setContentType($type); if (!$this->getFileName()) { $this->setFileName($data->getFileName()); } }