Пример #1
0
 /**
  * @param $file
  * @param $accountId
  * @throws \Exception
  */
 public function addPictureFromRequest($file, $accountId)
 {
     $picture = $file->get('file');
     $adapter = new Http();
     $size = new Size(array('max' => $this::MAXIMUM_PICTURE_SIZE));
     //$extension = new Extension(array('extension' => array('jpeg', 'jpg', 'gif', 'tiff', 'png', 'bmp')));
     $adapter->setValidators(array($size), $picture['name']);
     if (!$adapter->isValid()) {
         $errors = $adapter->getMessages();
         $message = '';
         foreach ($errors as $error) {
             $message .= $error;
             break;
         }
         throw new \Exception($message);
     }
     $tmpFileUrl = $accountId . '_logo.jpg';
     $destinationFolder = dirname(__DIR__) . $this::UPLOAD_FOLDER;
     $destinationFile = $destinationFolder . "/" . $tmpFileUrl;
     if (!file_exists($destinationFolder)) {
         mkdir($destinationFolder);
     }
     $adapter->addFilter('Rename', array('target' => $destinationFile, 'overwrite' => true));
     if (!$adapter->receive($picture['name'])) {
         throw new \Exception("An error was found while uploading the picture");
     }
 }
 public function postAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $product = new Product();
         $product->name = $request->getPost('name');
         $product->price = $request->getPost('price');
         $product->manufacture = $request->getPost('manufacture');
         $product->inventory_number = $request->getPost('inventory_number');
         $product->date = $request->getPost('date');
         $product->show = $request->getPost('show');
         // Get images
         $temp = array();
         $imgTotal = intval($request->getPost('imgTotal'));
         $httpadapter = new Http();
         $httpadapter->addValidator('Size', true, array('min' => 1000));
         $httpadapter->addValidator('Extension', true, array('png', 'jpg', 'jpeg'));
         for ($i = 0; $i < $imgTotal; $i++) {
             $fileName = 'image_' . $i;
             $image = $request->getFiles($fileName);
             $httpadapter->addFilter('Rename', array('target' => __UPLOAD__ . '/products/' . $product->name . '-' . $image['name'], 'randomize' => true));
             if ($httpadapter->isValid()) {
                 if ($httpadapter->receive($image['name'])) {
                     $temp[] = $httpadapter->getFileInfo()[$fileName]['name'];
                 }
             }
         }
         $product->images = implode(';', $temp);
         $product->display = $request->getPost('display');
         $product->os = $request->getPost('os');
         $product->cpu = $request->getPost('cpu');
         $product->camera = $request->getPost('camera');
         $product->internal_memory = $request->getPost('internal_memory');
         $product->ram = $request->getPost('ram');
         $product->battery = $request->getPost('battery');
         $product->more = $request->getPost('more');
         // Insert product
         if ($this->getProductTable()->insertProduct($product)) {
             echo json_encode('successful');
         } else {
             echo json_encode('Insert error');
         }
         exit;
     }
 }
Пример #3
0
 public function move($postdata)
 {
     if (!$postdata && !isset($postdata['filepath']) && !isset($postdata['destination'])) {
         throw new Exception("invalid input", '500');
     }
     $adapter = new Http();
     $adapter->addFilter('File\\Rename', array('target' => $postdata['destination'], 'use_upload_extension' => true, 'overwrite' => true));
     try {
         if ($adapter->receive()) {
             $file = $adapter->getFilter('File\\Rename')->getFile();
             echo $file[0]['target'];
         } else {
             throw new \Exception('Unable to upload file', '500');
         }
     } catch (\Exception $ex) {
         throw new \Exception($ex->getMessage(), '500');
     }
 }
 public function updateAction()
 {
     $id = $this->params()->fromRoute('id');
     $request = $this->getRequest();
     $message = null;
     if ($request->isPost()) {
         // Get file upload
         $files = $request->getFiles()->toArray();
         $filePostName = 'image';
         $file = $files[$filePostName];
         // Check validate
         $httpadapter = new Http();
         $httpadapter->addValidator('Size', true, array('min' => 1000), $filePostName);
         $httpadapter->addValidator('Extension', true, array('png', 'jpg', 'jpeg'), $filePostName);
         // Rename file upload
         $httpadapter->addFilter('Rename', array('target' => __UPLOAD__ . '/ads/' . $file['name'], 'randomize' => true), $filePostName);
         // Save file upload
         $newFileName = null;
         if ($httpadapter->isValid()) {
             if ($httpadapter->receive($file['name'])) {
                 $fileInfo = $httpadapter->getFileInfo();
                 $newFileName = $fileInfo[$filePostName]['name'];
             }
         }
         $adsPost = new Advertise();
         $adsPost->id = $id;
         $adsPost->image = $newFileName;
         $adsPost->link = $request->getPost('link');
         $adsPost->date_start = $request->getPost('date_start');
         $adsPost->date_end = $request->getPost('date_end');
         $adsPost->location = $request->getPost('location');
         $adsPost->show = $request->getPost('show');
         $adsPost->view_count = $request->getPost('view_count');
         $adsPost->click_count = $request->getPost('click_count');
         $result = $this->getAdvertiseTable()->updateAdvertise($adsPost);
         if ($result) {
             $message = 'Successful!';
         } else {
             $message = 'Error!! Please try again.';
         }
     }
     $ads = $this->getAdvertiseTable()->getAdvertiseById($id);
     return new ViewModel(array('ads' => $ads, 'message' => $message));
 }
 public function updateAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Get file upload
         $files = $request->getFiles()->toArray();
         $logo = $files['logo'];
         // Check validate
         $httpadapter = new Http();
         $httpadapter->addValidator('Size', true, array('min' => 1000));
         $httpadapter->addValidator('Extension', true, array('png', 'jpg', 'jpeg'));
         // Rename file upload
         $httpadapter->addFilter('Rename', array('target' => __UPLOAD__ . '/page/' . $logo['name'], 'randomize' => true));
         // Save file upload
         $newFileName = null;
         if ($httpadapter->isValid()) {
             if ($httpadapter->receive($logo['name'])) {
                 $fileInfo = $httpadapter->getFileInfo();
                 $newFileName = $fileInfo['logo']['name'];
             }
         }
         $data = new Info();
         $data->name = $request->getPost('name');
         if (isset($newFileName)) {
             $data->logo = '/upload/page/' . $newFileName;
         } else {
             $data->logo = null;
         }
         $data->address = $request->getPost('address');
         $data->tel = $request->getPost('tel');
         $data->introduce = $request->getPost('introduce');
         $data->image = $request->getPost('image');
         $this->getInfoTable()->updateInfo($data);
     }
     $this->redirect()->toRoute('shopinfo');
 }
 public function editAction()
 {
     try {
         $id = $this->params('id', false);
         $em = $this->getEntityManager();
         if ($id) {
             $form = new RecruitmentForm($em);
             $recruitment = $em->find('Recruitment\\Entity\\Recruitment', $id);
             $currentDate = new \DateTime();
             $beginDate = \DateTime::createFromFormat('d/m/Y', $recruitment->getRecruitmentBeginDate());
             if ($beginDate <= $currentDate) {
                 return new ViewModel(array('message' => 'Não é possível editar processos seletivos concluídos ou em andamento. Por favor, consulte o administrador do sistema.', 'form' => null));
             }
             $form->bind($recruitment);
             $request = $this->getRequest();
             if ($request->isPost()) {
                 $publicNotice = $recruitment->getRecruitmentPublicNotice();
                 $fileContainer = $request->getFiles()->toArray();
                 $file = $fileContainer['recruitment']['recruitmentPublicNotice'];
                 $data = $request->getPost();
                 $form->setData($data);
                 if ($form->isValid() && !$file['error'] && $file['size']) {
                     try {
                         $filename = $data['recruitment']['recruitmentYear'] . $data['recruitment']['recruitmentNumber'] . $data['recruitment']['recruitmentType'] . '.pdf';
                         $recruitment->setRecruitmentPublicNotice($filename);
                         $em->persist($recruitment);
                         $em->flush();
                         $targetDir = self::PUBLIC_NOTICE_DIR;
                         $targetFile = $targetDir . $filename;
                         if (file_exists($targetFile)) {
                             unlink(self::PUBLIC_NOTICE_DIR . $publicNotice);
                         }
                         $uploadAdapter = new HttpAdapter();
                         $uploadAdapter->addFilter('File\\Rename', array('target' => $targetFile, 'overwrite' => true));
                         $uploadAdapter->setDestination($targetDir);
                         if (!$uploadAdapter->receive($fileContainer['name'])) {
                             $messages = implode('\\n', $uploadAdapter->getMessages());
                             throw new \RuntimeException($messages);
                         }
                         return $this->redirect()->toRoute('recruitment/recruitment', array('action' => 'index'));
                     } catch (\Thrownable $ex) {
                         if ($ex instanceof UniqueConstraintViolationException) {
                             return new ViewModel(array('message' => 'Este processo seletivo já foi cadastrado.', 'form' => null));
                         }
                         return new ViewModel(array('message' => 'Erro inesperado: ' . $ex->getMessage(), 'form' => null));
                     }
                 }
                 return new ViewModel(array('message' => $file['error'] || !$file['size'] ? 'O upload do edital não pode ser feito. Por favor tente novamente.' : null, 'form' => $form));
             }
             return new ViewModel(array('form' => $form, 'message' => null));
         }
         return new ViewModel(array('form' => null, 'message' => 'Nenhum Processo Seletivo foi escolhido'));
     } catch (\Exception $ex) {
         return new ViewModel(array('form' => null, 'message' => $ex->getMessage()));
     }
 }
Пример #7
0
 /**
  * image upload
  */
 public function uploadAction()
 {
     if ($this->getRequest()->isPost()) {
         if (!is_dir($this->path . $this->locador->getId())) {
             mkdir($this->path . $this->locador->getId());
         }
         $fileTransfer = new FileTransfer();
         $arquivo = $fileTransfer->getFileInfo('fachada');
         //unlink($this->path.$this->locador->getId().'/original.' . strtolower(substr($arquivo['fachada']['name'], -3, 3)));
         $fileTransfer->setDestination($this->path . $this->locador->getId());
         $fileTransfer->addFilter('Rename', array('target' => 'original.' . strtolower(substr($arquivo['fachada']['name'], -3, 3)), 'overwrite' => true));
         $fileTransfer->receive();
         $this->redirect()->toRoute('Locador/imovel/novo', array('etapa' => 3));
     }
 }
Пример #8
0
 public function addAction()
 {
     if ($this->getLoginTable()->validarSessao()) {
         $this->redirect()->toRoute('login');
     }
     $adapter = new Http();
     $destino = dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/public/img/fotos/';
     $adapter->setDestination($destino);
     $request = $this->getRequest();
     $titulo = $id_update = $pasta = $hidden = $saida = null;
     if ($request->isPost()) {
         $titulo = $request->getPost('titulo');
         $titulo = str_replace("/", "-", $titulo);
         $id_update = $request->getPost('id');
         date_default_timezone_set('America/Sao_Paulo');
         $pasta = date("dmYHis");
         $files = $adapter->getFileInfo();
         if (!empty($files)) {
             mkdir($destino . $pasta . '/', 0777);
             $qtd = 0;
             foreach ($files as $file => $info) {
                 //$adapter->addFilter('Rename', $destino . $pasta . '/' . $info['name']);
                 $adapter->addFilter('Rename', $destino . $pasta . '/' . $qtd . '.jpg');
                 $adapter->receive($file);
                 $this->lista[$qtd] = '/nortes/public/img/fotos/' . $pasta . '/' . $qtd . '.jpg';
                 $qtd++;
             }
             $saida = $this->getPortfolioTable()->printFormulario($this->lista, $titulo, $pasta, null, null);
             $hidden = 'hidden = "true" ';
         } else {
             if (!is_null($id_update)) {
                 $fotos_update = $this->getFotosTable()->changeFotos($id_update);
                 $qtd = 0;
                 $id_fotos = array();
                 foreach ($fotos_update as $ft) {
                     $this->lista[$qtd] = '/nortes/public/img/fotos/' . $id_update . '/' . $ft['id'] . '.jpg';
                     $id_fotos[$qtd] = $ft;
                     $qtd++;
                 }
                 $hidden = 'hidden = "true" ';
                 $saida = $this->getPortfolioTable()->printFormulario($this->lista, $titulo, null, $id_update, $id_fotos);
             }
         }
         return array('titulo' => $titulo, 'saida' => $saida, 'hidden' => $hidden);
     }
 }
Пример #9
0
 /**
  * @param int $userId - used to create a folder for the current user and rename the image
  *
  * @return void
  */
 private function uploadImage($userId = 0)
 {
     $userId = (int) $userId;
     $messages = [];
     $dir = 'public/userfiles/images/user-' . $userId . '/';
     $adapter = new Http();
     $size = new Size(['min' => '10kB', 'max' => '5MB', 'useByteString' => true]);
     $extension = new Extension(['jpg', 'gif', 'png', 'jpeg', 'bmp', 'webp', 'svg'], true);
     if (!is_dir($dir)) {
         mkdir($dir, 0750, true);
     }
     foreach ($adapter->getFileInfo() as $file) {
         $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
         $newName = $userId . '.' . $ext;
         $adapter->setValidators([$size, new IsImage(), $extension]);
         $adapter->addFilter('File\\Rename', ['target' => $dir . $newName, 'overwrite' => true]);
         $adapter->receive($file['name']);
         if (!$adapter->isReceived($file['name']) && $adapter->isUploaded($file['name'])) {
             $messages[] = $file['name'] . ' was not uploaded';
         }
     }
     $this->setLayoutMessages($messages, 'info');
 }