php - ZF2 fileupload - File never stored -
hello have following setup, adjusted zf2fileupload example on zf2fileuploadexamples controller:
public function addaction() { $objectmanager = $this->getservicelocator()->get('doctrine\orm\entitymanager'); $form = new createeventform($objectmanager); $event = new event(); $form->bind($event); if ($this->getrequest()->ispost()) { // merge files $post = array_merge_recursive( $this->getrequest()->getpost()->toarray(), $this->getrequest()->getfiles()->toarray() ); $form->setdata($post); if ($form->isvalid()) { return $this->redirecttosuccesspage($form->getdata()); } return new viewmodel(array( 'event' => $event, 'form' => $form )); }
inputfilter file filter part:
private function addfile() { $name = '/event'; $path = application_path . '/../data/upload/'; $target = realpath($path) . $name; // file input $input = new fileinput('image'); $input->setrequired(true); $input->setallowempty(false); // filters $renameupload = new renameupload($target); $renameupload->setoverwrite(false); $renameupload->setuseuploadextension(true); $renameupload->setuseuploadname(true); $renameupload->setrandomize(true); // file input $input->getfilterchain()->attach($renameupload); //validators $this->add($input); return $this; }
in dump of success page see:
file upload success
object(entities\event)[323] private 'id' => null private 'title' => string 'event10' (length=7) private 'eventinfo' => string 'event 10' (length=8) private 'image' => array (size=1) 0 => array (size=5) 'name' => string 'test.jpg' (length=38) 'type' => string 'image/jpeg' (length=10) 'tmp_name' => string '/tmp/phpjwizws' (length=14) 'error' => int 0 'size' => int 257860 private 'eventdate' => object(datetime)[324] public 'date' => string '2015-04-11 00:00:00' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'europe/berlin' (length=13) private 'webshop' => null
-- edit -- wilt on right track, inputfilter never called. seems called, return form , generates message no files selected
any suggestions?
i have 2 questions:
- according examples file should saved, if in /data/upload there no files. wrong?
- after having saved file how can obtain full file name storing in database (i have set rename filter randomize) , @ point available?
Comments
Post a Comment