/** * 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(); } }
public function __construct($delete_url, $options) { $this->delete_url = $delete_url; $opts = CustomUploadHandler::getDefaultOptions(); if (array_key_exists('image_versions', $options) && is_null($options['image_versions'])) { $options['image_versions'] = array(); } if (array_key_exists('upload_dir', $options)) { $options['upload_url'] = $this->getFullUrl() . '/' . $options['upload_dir']; $options['upload_dir'] = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $options['upload_dir']; } if ($options != null) { $opts = array_merge($opts, $options); } parent::__construct($opts, false, null); }