コード例 #1
0
 public function uploadAction()
 {
     $this->init();
     if (!is_dir($this->_dir)) {
         mkdir($this->_dir, 0777);
     }
     $form = new UploadForm($this->getServiceLocator(), $this->_dir, 'upload-form');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             // Form is valid, save the form!
             $this->setFileNames($data);
             // The data can be saved in the DataBase
             return $this->redirect()->toRoute('uploads');
         }
     }
     return new ViewModel(array('form' => $form));
 }
コード例 #2
0
 public function uploadFormAction()
 {
     $form = new UploadForm('upload-form');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             // Form is valid, save the form!
             return $this->redirect()->toRoute('product');
         }
     }
     return array('form' => $form);
 }