public function processAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Make certain to merge the files info!
         $File = $this->params()->fromFiles('image-file');
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form = $this->getServiceLocator()->get('UploadForm');
         $form->setData($post);
         if ($form->isValid()) {
             // $data = $form->getData();
             // $size = new Size(array('min'=>2000000)); //minimum bytes filesize
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             //validator can be more than one...
             //$adapter->setValidators($File['name']);
             $adapter->setDestination($this->getFileUploadLocation());
             if ($adapter->receive($File['name'])) {
                 $uploadTable = $this->getServiceLocator()->get('UploadTable');
                 $userTable = $this->getServiceLocator()->get('UserTable');
                 $authService = $this->getServiceLocator()->get('AuthService');
                 $userEmail = $authService->getStorage()->read();
                 $user_info = $userTable->getUserByEmail($userEmail);
                 $upload_data = array('user_id' => $user_info["users_id"], 'label' => 'prazno ne unosim iz forme', 'filename' => $post["image-file"]["name"]);
                 $upload = new Upload();
                 $upload->exchangeArray($upload_data);
                 $uploadTable->saveUpload($upload);
             }
             // Form is valid, save the form!
             //return $this->redirect()->toRoute('upload-form/success');
         }
         return $this->redirect()->toRoute('uploads', array('action' => 'prva'));
     }
 }
 public function processUploadAction()
 {
     $userTable = $this->getServiceLocator()->get('UserTable');
     $user_email = $this->getAuthService()->getStorage()->read();
     $user = $userTable->getUserByEmail($user_email);
     $form = $this->getServiceLocator()->get('UploadForm');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $upload = new Upload();
         $uploadFile = $this->params()->fromFiles('fileupload');
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // Fetch Configuration from Module Config
             $uploadPath = $this->getFileUploadLocation();
             // Save Uploaded file
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $adapter->setDestination($uploadPath);
             if ($adapter->receive($uploadFile['name'])) {
                 $exchange_data = array();
                 $exchange_data['label'] = $request->getPost()->get('label');
                 $exchange_data['filename'] = $uploadFile['name'];
                 $exchange_data['user_id'] = $user->id;
                 $upload->exchangeArray($exchange_data);
                 $uploadTable = $this->getServiceLocator()->get('UploadTable');
                 $uploadTable->saveUpload($upload);
                 return $this->redirect()->toRoute('users/upload-manager', array('action' => 'index'));
             }
         }
     }
     return array('form' => $form);
 }
 public function uploadAction()
 {
     $this->_loginedInUser();
     $this->uploadTable = $this->getServiceLocator()->get('UploadTable');
     $form = $this->getServiceLocator()->get('UploadForm');
     if ($this->request->isPost()) {
         $form->setData($this->request->getPost());
         $uploadFile = $this->params()->fromfiles('filename');
         if ($form->isValid()) {
             $uploadPath = $this->getFileUploadLocation();
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $adapter->setDestination($uploadPath);
             if ($adapter->receive($uploadFile['name'])) {
                 // File upload sucessfully
                 $exchange_data = array();
                 $exchange_data['label'] = $this->request->getPost('label');
                 $exchange_data['filename'] = $uploadFile['name'];
                 $exchange_data['user_id'] = $this->user->id;
                 $upload = new Upload();
                 $upload->exchangeArray($exchange_data);
                 $this->uploadTable->saveUpload($upload);
                 $this->redirect()->toRoute(null, array('controller' => 'upload-manager', 'action' => 'index'));
             }
         }
     }
     $viewModel = new ViewModel(array('form' => $form));
     return $viewModel;
 }
 protected function createUpload(array $data)
 {
     $sm = $this->getServiceLocator();
     $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
     $resultSetPrototype = new \Zend\Db\ResultSet\ResultSet();
     $resultSetPrototype->setArrayObjectPrototype(new \Users\Model\Upload());
     $tableGateway = new \Zend\Db\TableGateway\TableGateway('upload', $dbAdapter, null, $resultSetPrototype);
     $upload = new Upload();
     $upload->exchangeArray($data);
     $uploadTable = new UploadTable($tableGateway);
     $uploadTable = $this->getServiceLocator()->get('UploadTable');
     $uploadTable->saveUpload($upload);
     return true;
 }
 public function exchangeArray($data)
 {
     parent::exchangeArray($data);
     $this->thumbnail = isset($data['thumbnail']) ? $data['thumbnail'] : null;
 }