/** * Upload new Images * * Also updates Category & Album modification times * * @param int $categoryId * @param int $albumId */ public function create($categoryId, $albumId) { $category = $this->getCategoryFinder()->findOneBy('id', $categoryId); $album = $this->getAlbumFinder()->findOneBy('id', $albumId); if ($this->slim->request->isGet()) { $this->slim->render('image/create.html.twig', ['category' => $category, 'album' => $album, 'sessionUser' => $this->getSessionUser(), 'allowedExtensions' => Image::getAllowedExtensions(true)]); } elseif ($this->slim->request->isPost()) { $uploadHandler = new CustomUploadHandler(['upload_dir' => ROOT . '/files/', 'upload_url' => null, 'access_control_allow_methods' => ['POST'], 'accept_file_types' => '/\\.(' . Image::getAllowedExtensions(true) . ')$/i', 'image_library' => 0, 'image_versions' => ['' => ['auto_orient' => false], 'thumb' => ['upload_dir' => ROOT . '/files/thumbs/', 'upload_url' => null, 'crop' => true, 'max_width' => 252, 'max_height' => 252]]]); $newImage = new Image($this->slim->db); $newImage->setAlbumId($album->getId()); $newImage->setName($uploadHandler->getUploadedFileName()); $newImage->insert(); $album->update(); $category->update(); } }