Beispiel #1
0
 public function processAction()
 {
     if (!$this->request->isPost()) {
         return $this->redirect()->toRoute(NULL, array('controller' => 'upload', 'action' => 'index'));
     }
     //$post = $this->request->getPost();
     //$request = $this->getRequest();
     //Création du formulaire
     $form = new UploadForm();
     //récupération de l'objet de travail
     //$uploadFile = new File();
     $uploadFile = $this->params()->fromFiles('fileupload');
     $form->setData($this->{$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'])) {
             // File upload sucessfull
             $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'));
         }
         /*
                     $post = $this->request->getPost();
                     $form = new UploadForm();
                     // to get Login Form
                   // $form = $this->getServiceLocator()->get('LoginForm');
         
                     
                     $inputFilter = new UploadFilter();
                     $form->setInputFilter($inputFilter);
                     $form->setData($post);
                         if (!$form->isValid()) {
           $model = new ViewModel(array(
             'error' => true,
              'form' => $form,
                    ));
         
                      $model->setTemplate('users/upload/index');
                  return $model;
          }
          
          // Créer l'utisateur avant la page de  confirmation  
           $this->createUpload($form->getData());
         
            return $this->redirect()->toRoute(NULL , array(
            'controller' => 'upload',
                'action' => 'confirm'
                          ));
         */
     }
 }
 public function processAction()
 {
     $userEmail = $this->getAuthService()->getStorage()->read();
     if (!$userEmail) {
         $this->flashMessenger()->addErrorMessage("not authorized");
         return $this->redirect()->toRoute('media', array('action' => 'index'));
     }
     $request = $this->getRequest();
     $form = new UploadForm();
     $uploadFile = $this->params()->fromFiles('fileupload');
     $form->setData($request->getPost());
     if ($form->isValid()) {
         // Получение конфигурации из конфигурационных данных модуля
         $uploadPath = $this->getFileUploadLocation();
         // Сохранение выгруженного файла
         $adapter = new \Zend\File\Transfer\Adapter\Http();
         $adapter->setDestination($uploadPath);
         if ($adapter->receive($uploadFile['name'])) {
             $userTable = $this->getServiceLocator()->get('UserTable');
             $user = $userTable->getUserByEmail($userEmail);
             //                // Успешная выгрузка файла
             $exchange_data = array();
             $exchange_data['label'] = $request->getPost()->get('label');
             $exchange_data['filename'] = $uploadFile['name'];
             $exchange_data['user_id'] = $user->getId();
             $imageUpload = new \Users\Model\ImageUpload();
             $thumbnailFileName = $this->generateThumbnail($uploadFile['name']);
             $thumbnail_data = $exchange_data;
             $thumbnail_data['thumbnail'] = $thumbnailFileName;
             $imageUpload->exchangeArray($thumbnail_data);
             $imageUploadTable = $this->getServiceLocator()->get('ImageUploadTable');
             $imageUploadTable->save($imageUpload);
         }
     }
     return $this->redirect()->toRoute('media', array('action' => 'index'));
 }
 public function processAction()
 {
     $userEmail = $this->getAuthService()->getStorage()->read();
     if (!$userEmail) {
         $this->flashMessenger()->addErrorMessage("not authorized");
         return $this->getResponse()->setContent("not authorized");
     }
     $request = $this->getRequest();
     $form = new UploadForm();
     $uploadFile = $this->params()->fromFiles('fileupload');
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // Получение конфигурации из конфигурационных данных модуля
             $uploadPath = $this->getFileUploadLocation();
             // Сохранение выгруженного файла
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $adapter->setDestination($uploadPath);
             if ($adapter->receive($uploadFile['name'])) {
                 $userTable = $this->getServiceLocator()->get('UserTable');
                 $user = $userTable->getUserByEmail($userEmail);
                 $upload = new \Users\Model\Upload();
                 // Успешная выгрузка файла
                 $exchange_data = array();
                 $exchange_data['label'] = $request->getPost()->get('label');
                 $exchange_data['filename'] = $uploadFile['name'];
                 $exchange_data['user_id'] = $user->getId();
                 $upload->exchangeArray($exchange_data);
                 $uploadTable = $this->getServiceLocator()->get('UploadTable');
                 $uploadTable->save($upload);
                 $upload->setId($uploadTable->getLastInsertValue());
                 //добавить в Lucene
                 $searchIndexLocation = $this->getIndexLocation();
                 $index = Lucene\Lucene::create($searchIndexLocation);
                 // создание полей lucene
                 $fileUploadId = Document\Field::unIndexed('upload_id', $upload->getId());
                 $label = Document\Field::Text('label', $upload->getLabel());
                 $owner = Document\Field::Text('owner', $user->getName());
                 $uploadPath = $this->getFileUploadLocation();
                 $fileName = $upload->getFilename();
                 $filePath = $uploadPath . DIRECTORY_SEPARATOR . $fileName;
                 if (substr_compare($fileName, ".xlsx", strlen($fileName) - strlen(".xlsx"), strlen(".xlsx")) === 0) {
                     // Индексирование таблицы excel
                     $indexDoc = Lucene\Document\Xlsx::loadXlsxFile($filePath);
                 } else {
                     if (substr_compare($fileName, ".docx", strlen($fileName) - strlen(".docx"), strlen(".docx")) === 0) {
                         // Индексирование документа Word
                         $indexDoc = Lucene\Document\Docx::loadDocxFile($filePath);
                     } else {
                         $indexDoc = new Lucene\Document();
                     }
                 }
                 // создание нового документа и добавление всех полей
                 $indexDoc = new Lucene\Document();
                 $indexDoc->addField($label);
                 $indexDoc->addField($owner);
                 $indexDoc->addField($fileUploadId);
                 $index->addDocument($indexDoc);
                 $index->commit();
             }
         }
     }
     return $this->redirect()->toRoute('uploads', array('action' => 'index'));
 }