我无法以zend格式上传图片,也无法将图像保存在数据库中。请帮我转发代码
答案 0 :(得分:2)
public function getLogoForm()
{
//Create Form
$form = new Zend_Form();
$form->setAction('logoupdate');
$form->setMethod('post');
$form->setAttrib('enctype', 'multipart/form-data');
$form->setAttrib('sitename', 'hostname');
$logo = new Zend_Form_Element_File('logo');
$logo->setDecorators(array('File',
array(array('data'=>'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
));
$logo->setLabel('Logo (png) ');
$logo->setRequired(true);
$logo->setDestination('includes/images/logo/');
$logo->addValidator('Count', false, 1);
$logo->addValidator('Extension', false, 'png');
$form->addElement($logo);
//Create a submit button.
$form->addElement('submit', 'submit');
$submitElement = $form->getElement('submit');
$submitElement->setAttrib('class',"button");
$submitElement->setDecorators(array('ViewHelper',
'Description',
'Errors', array(array('data'=>'HtmlTag'), array('tag' => 'td',
'colspan'=>'2','align'=>'right')),
array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
));
$submitElement->setLabel('Change Logo');
$form->setDecorators(array('FormElements',
array(array('data'=>'HtmlTag'),array('tag'=>'table')), 'Form'
));
//Return the form
return $form;
}
ChangelogoAction
$form = $this->getLogoForm();
$this->view->Lform = $Lform;
logoupdateAction
$form = $this->getLogoForm();
if($form->isValid($_POST)){
$form->logo->receive();
$this->view->success = array('logo' => 'Logo has been changed');
} else {
$this->view->errors = $form->getMessages();
$this->view->form = $form;
$this->render("changelogo");
}
答案 1 :(得分:0)
上传时遇到的一个常见问题是当enctype未设置为表单标记内的multipart / form-data时。