我有一个集成到CMS页面的自定义注册表单,通过该表单,如果用户创建一个帐户,他将被分配一个特殊的客户组。 我想创建一个图像上传表单,通过该表单,客户可以在通过该表单注册时上传他的身份证图片。
该图片将存储在Media / Customer目录中,或通过电子邮件作为附件发送。
我是新手,所以我们将非常感谢您的完整指南。
谢谢,
答案 0 :(得分:0)
1 - 将以下代码放入您的表单
<input type="file" name="customerimg" value="" />
在您的控制器中,在帖子操作中放置代码
public function postAction()
{ $post = $this->getRequest()->getPost();
if ( $post ) {
if (isset($_FILES)){
if ($_FILES['customerimg']['name']) {
$path = Mage::getBaseDir('media') . DS . Customer . DS;
$uploader = new Varien_File_Uploader('customerimg');
$uploader->setAllowedExtensions(array('jpg','png','gif'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path.$_FILES['customerimg']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
}
}
$model = Mage::getModel('yourmodel')->setData($post);
$model->save();
$mail = new Zend_Mail('utf-8');
$recipients = array(
Mage::getStoreConfig('trans_email/ident_custom1/name') => Mage::getStoreConfig('trans_email/ident_custom1/email'),
Mage::getStoreConfig('trans_email/ident_custom2/name') => Mage::getStoreConfig('trans_email/ident_custom2/email'),
);
$mailBody = "<b>Error Code: </b>" . $errorCod . "<br />
";
$mailBody .= "<b>Error Massage: </b>" . $errorMsg . "<br />
";
$mail->setBodyHtml($mailBody)
->setSubject('Lorem Ipsum')
->addTo($recipients)
->setFrom(Mage::getStoreConfig('trans_email/ident_general/email'), "FromName");
//file content is attached
$file = Mage::getBaseDir('media') . DS . Customer . DS . $filename;
$attachment = file_get_contents($file);
$mail->createAttachment(
$attachment,
Zend_Mime::TYPE_OCTETSTREAM,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
'attachment_1.log'
);
try {
$mail->send();
} catch (Exception $e) {
Mage::logException($e);
}
}
}