示例#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);
             }
         }
     }
 }
示例#2
0
 public function projectAction()
 {
     $id = (int) $this->dispatcher->getParam('id', 'int');
     $imagePos = (int) $this->request->getQuery('image', 'int', 1);
     $project = Project::findFirst(array("id = {$id} AND visible = '1'", array('cache' => array('key' => md5("Project::findById({$id})"), 'lifetime' => 60))));
     if (!$project) {
         throw new Exception("Project ID = {$id} not found");
     }
     $projectImage = ProjectImage::find(array("conditions" => "project_id = {$id}", "order" => "id ASC", "limit" => array("number" => 1, "offset" => $imagePos - 1)));
     $this->helper->title()->append($project->getTitle());
     $this->helper->title()->append('Галерея проектов');
     $this->view->imagePos = $imagePos;
     $this->view->project = $project;
     $this->view->projectImage = $projectImage[0];
 }