public function createAndUploadPhoto(Gallery $gallery, array $values, \Nette\Web\HttpUploadedFile $file) { if (!$file->isImage()) { throw new ValidationException("Soubor není obrázek."); } $photo = $this->createBlank(); $this->update($photo, $values); $gallery->addPhoto($photo); @mkdir(pathinfo($photo->getFilePath(), PATHINFO_DIRNAME), 0777, true); $file->toImage()->resize($this->maxWidth, $this->maxHeight)->save($photo->getFilePath()); $this->save($gallery); }
public function uploadPhoto(Gallery $gallery, array $values, \Nette\Web\HttpUploadedFile $file) { if (!$file->isImage()) { throw new \Neuron\Model\ValidationException("File is not image."); } // save image $image = $file->toImage()->resize($this->maxWidth, $this->maxHeight); $values['hash'] = $this->repository->save((string) $image); // save entity $em = $this->getEntityManager(); $photo = new Photo($values); $em->persist($photo); $gallery->addPhoto($photo); $em->flush(); }