Ejemplo n.º 1
0
 private function uploadImage($model)
 {
     if ($this->request->isPost()) {
         if ($this->request->hasFiles() == true) {
             foreach ($this->request->getUploadedFiles() as $file) {
                 if (!in_array($file->getType(), array('image/bmp', 'image/jpeg', 'image/png'))) {
                     return $this->flash->error('Разрешается загружать только файлы с расширением jpg, jpeg, png, bmp');
                 }
                 $projectImage = new ProjectImage();
                 $projectImage->setProjectId($model->getId());
                 $projectImage->create();
                 $imageFilter = new \Image\Filter(array('id' => $projectImage->getId(), 'type' => 'project'));
                 $resize_x = 1000;
                 $resize_y = 1000;
                 $successMsg = 'Фото добавлено';
                 $imageFilter->removeCached();
                 require_once __DIR__ . '/../../Image/vendor/PHPThumb/ThumbLib.inc.php';
                 $thumb = \PhpThumbFactory::create($file->getTempName());
                 $thumb->resize($resize_x, $resize_y);
                 $thumb->save($imageFilter->originalAbsPath());
                 $this->flash->success($successMsg);
             }
         }
     }
 }