Ejemplo n.º 1
0
 public function uploadAction()
 {
     $this->view->disable();
     if ($this->request->hasFiles(true) == false) {
         $this->getDi()->getFlashSession()->error("Please select image, category and try again!");
         $this->view->setVar('flash', $this->flash);
         return $this->response->redirect('admin');
     }
     if ($this->request->isPost()) {
         foreach ($this->request->getUploadedFiles() as $file) {
             $file->moveTo('/public/img/' . $file->getName());
             $galleryFileName = '/public/img/' . $file->getName();
         }
         $data = array('name' => $galleryFileName, 'cat_id' => $this->request->getPost()['category']);
         //Insert record at gallery model from post rq
         $galleryModel = new Gallery();
         if (!$galleryModel->save($data)) {
             $galleryModel->setErr();
             $this->view->setVar('flash', $this->flash);
         } else {
             $this->getDi()->getFlashSession()->success("Done!");
         }
     }
     return $this->response->redirect('admin');
 }
 public function uploadAction()
 {
     if ($this->request->hasFiles() == true) {
         foreach ($this->request->getUploadedFiles() as $file) {
             $file->moveTo('/var/www/Agency-website/public/img/' . $file->getName());
             $galleryFileName = '/var/www/Agency-website/public/img/' . $file->getName();
         }
         //Insert record at gallery model from post rq
         $this->request->getPost();
         $galleryModel = new Gallery();
         $galleryModel->setName($galleryFileName)->setCatId($this->request->getPost()['category']);
         if (!$galleryModel->save()) {
             //flashErrors
             $this->flash->error("No category selected!");
         } else {
             //flashErrors
             $this->flash->success("DONE!");
         }
     }
 }
 public function createAction()
 {
     $this->view->disable();
     if ($this->request->hasFiles(true) == false) {
         $this->getDi()->getFlashSession()->error('Pleas select an image');
         return $this->response->redirect('admin');
     }
     if ($this->request->isPost()) {
         $productsModel = new Products();
         $productsModel->setName($this->request->getPost()['name'])->setCat($this->request->getPost()['category'])->setDescription($this->request->getPost()['description'])->setPrice($this->request->getPost()['price']);
         if (!$productsModel->save()) {
             $productsModel->setErr();
         }
         $folder = $this->request->getPost()['category'];
         if (!is_dir(__DIR__ . '/../../public/img/products/' . $folder . '/')) {
             mkdir(__DIR__ . '/../../public/img/products/' . $folder . '/', 0777);
         }
         foreach ($this->request->getUploadedFiles() as $file) {
             $galleryFileName = time() . '_' . $file->getName();
             $fullpath = __DIR__ . '/../../public/img/products/' . $folder . '/' . $galleryFileName;
             $file->moveTo($fullpath);
             $image = new \Phalcon\Image\Adapter\GD($fullpath);
             $image->resize(200, 200)->crop(200, 200);
             if (!$image->save()) {
                 var_dump($image);
                 exit;
             }
         }
         $data = array('name' => $galleryFileName, 'cat_id' => $this->request->getPost()['category'], 'product_id' => $productsModel->getId());
         //Insert record at gallery model from post rq
         $galleryModel = new Gallery();
         if (!$galleryModel->save($data)) {
             $galleryModel->setErr();
         }
     }
     //        $this->view->setVar('flash', $this->flash);
     return $this->response->redirect('admin');
 }