php - Zend Form File upload won't validate or upload files -
i'm trying file upload zend form, cannot file uploads work.
here's form code:
public function __construct($options = null) { parent::__construct($options); $this->setname('modelupload'); $this->setmethod('post'); $this->setaction('/model/upload'); $this->setattrib('enctype', 'multipart/form-data'); // ... other elements ... // $file = new zend_form_element_file('file'); $file ->setattrib('title', 'select file upload.') ->setattrib('required',"") ->setrequired(true) ->addvalidator('count',false,1) ->addvalidator('size',false,104857600) ->setmaxfilesize(104857600) ->setvaluedisabled(true) ->setdestination(application_path . "/../data/models/temp/") ->setlabel('select file upload.'); $submit = new zend_form_element_submit('submit', array( 'label' => 'upload' )); $submit->removedecorator('dtddwrapper'); $this->setdecorators( array( array('viewscript', array('viewscript' => 'formviews/_form_upload_model.phtml')))); $this->addelements(array($name, $description, $file, $submit)); }
and here controller code:
public function uploadaction() { // action body error_reporting(e_all); $this->view->pagetitle = "model upload"; $form = new application_model_formmodelupload(); if ($this->_request->ispost()) { $formdata = $this->_request->getpost(); if ($form->isvalid($formdata)) { echo "<h1>valid</h1>"; $upload = new zend_file_transfer(); $files = $upload->getfileinfo(); $form->getvalues(); } else { echo "<h1>not valid</h1>"; } echo "<pre>"; print_r($formdata); echo "</pre>"; } $this->view->form = $form; }
and when try , upload something, this:
not valid array ( [name] => title [description] => description [max_file_size] => 104857600 [file] => filename.extension [submit] => upload )
i.e form not passing validation , have no idea why. aside this, file isn't being uploaded. i've tried many things , i'm @ wit's end. i'm using zend server ce on local environment if makes difference.
i thank in advance can offer!
edit:
tried miss poo's code below , got this:
array ( ) array ( [name] => array ( ) [description] => array ( ) [file] => array ( ) [submit] => array ( ) ) array ( )
absolutely no errors being returned...
i had same issee, when removed setmaxfilesize(104857600)
form got error [fileuploaderrorinisize] => file 'image' exceeds defined ini size
, had change php.ini config , add form enctype="multipart/form-data"
.
Comments
Post a Comment