我无法以 zend 形式上传图像,也无法将图像保存在数据库中。请帮助我并转发代码
问问题
2191 次
2 回答
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;
}
Changelogo动作
$form = $this->getLogoForm();
$this->view->Lform = $Lform;
logoupdate动作
$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");
}
于 2012-07-17T14:33:31.683 回答
0
上传的一个常见问题是在表单标签内将 enctype 设置为 multipart/form-data 时。
于 2012-06-06T10:36:14.690 回答