/** * it's not only handleGallerySaveImage now. We use it for save texy images too */ public function handleSaveImage() { if ($this->mainManager instanceof MagicManager && $this->mainManager->isGallery()) { $folder = $this->mainManager->getGalleryFolder(); } else { $this->error(); } if ($folder == '') { $folder = 'misc'; } $file = $this->httpRequest->getFile('Filedata'); if ($file && $file->isOk() && $this->detailObject) { // Save ... $year = date('Y'); $month = date('m'); $namespace = "{$folder}/{$year}/{$month}"; $this->imageStorage->setNamespace($namespace); $image = $this->imageStorage->save($file->getContents(), $file->getName()); $filename = pathinfo($image->getFile(), PATHINFO_BASENAME); $size = $image->getSize(); // Prepare thumbnail $this->imgPipe->setNamespace($namespace); $this->imgPipe->request($filename, '100x100', 'exact'); // Save to database $this->mainManager->addGalleryImage($filename, $namespace, $size->getWidth(), $size->getHeight(), $file->getContentType(), $this->detailObject->id); $response = ['status' => '1', 'height' => $size->getHeight(), 'width' => $size->getWidth(), 'mime' => $file->getContentType()]; } else { $response = ['status' => '0', 'error' => 'Error while uploading file', 'code' => 500]; } $this->sendJson($response); }
/** * @param Form $form * @throws ForbiddenRequestException */ public function articleFormSucceeded(Form $form) { $v = $form->getValues(); if (!$this->user->isAllowed('Article', 'add') || !$this->user->isAllowed('Article', 'edit')) { throw new ForbiddenRequestException(); } $tags = []; if ($v->tags !== '') { $articleTags = explode(',', $v->tags); $tags = $this->articleManager->createTagsAndReturnIds($articleTags); } // type if ($v->type != 'default') { $type = $this->articleManager->addTag($v->type, 'type'); } else { $type = NULL; } if ($v->draft) { $draft = TRUE; } else { $draft = FALSE; } if (empty($this->article)) { $article = $this->articleManager->addArticle($v->title, $v->content, $draft, $v->language, $tags, $type, $this->getUser()->getId()); $this->versionManager->addVersionToArticle($v->version, $article->id); $this->flashMessage('Article was added'); $this->redirect('Detail:default', $article->id, $article->slug); } else { // file upload if ($v->file->isOk()) { /** @var \Nette\Http\FileUpload $file */ $file = $v->file; // TODO : refactor $this->imageStorage->setNamespace("knowledgebase"); $filename = uniqid() . '.' . (pathinfo($file->name, PATHINFO_EXTENSION) ?: 'png'); $image = $this->imageStorage->save($file->getContents(), $filename); $returnPath = pathinfo($image->file, PATHINFO_BASENAME); $note = ''; if ($v->fileNote) { $note = $v->fileNote; } $status = $this->articleManager->assignImageToArticle($this->article->id, $returnPath, "knowledgebase", $note); if ($status) { $this->flashMessage('Image was uploaded'); } } $this->article = $this->articleManager->editArticle($this->article->id, $v->title, $v->content, $draft, $v->language, $tags, $type, $this->getUser()->getId()); // .. Update version $this->versionManager->updateVersion($v->version, $this->article->id); $this->flashMessage('Article was updated'); if (isset($form['sendAndView']) && $form['sendAndView']->isSubmittedBy()) { $this->redirect('Detail:default', $this->article->id, $this->article->slug); } else { $this->redirect('Edit:edit', $this->article->id); } } }
/** * TODO: refactor use Aprila/Brick/ImageManager */ public function handleSaveImage() { $this->imageStorage->setNamespace("texy"); $onlinePath = 'texy/'; $response = array(); /** @var \Nette\Http\FileUpload $file */ if ($file = $this->httpRequest->getFile('file')) { $filename = uniqid() . '.' . (pathinfo($file->name, PATHINFO_EXTENSION) ?: 'png'); $image = $this->imageStorage->save($file->getContents(), $filename); $returnPath = pathinfo($image->file, PATHINFO_BASENAME); if (FALSE) { // $this->someManager->assignImageToObject($this->object->id, $returnPath, "texy"); } $response['filename'] = $onlinePath . pathinfo($image->file, PATHINFO_BASENAME); } else { $response['error'] = 'Error while uploading file'; } $this->sendJson($response); }
public function handleSaveImage() { $file = $this->httpRequest->getFile('Filedata'); if ($file && $file->isOk()) { $year = date('Y'); $month = date('m'); $namespace = "project/{$year}/{$month}"; $this->imageStorage->setNamespace($namespace); $tempFilename = uniqid() . '.' . (pathinfo($file->getName(), PATHINFO_EXTENSION) ?: 'jpg'); $image = $this->imageStorage->save($file->getContents(), $tempFilename); $size = $image->getSize(); $colorInfo = $this->getImageColorInfo($image->getFile()); $filename = pathinfo($image->getFile(), PATHINFO_BASENAME); $this->addImage($filename, $namespace, $size->getWidth(), $size->getHeight(), $colorInfo, $file->getName(), $file->getContentType()); // Prepare thumbnail $this->imgPipe->setNamespace($namespace); $this->imgPipe->request($filename, '100x100', 'exact'); $response = ['status' => '1', 'height' => $size->getHeight(), 'width' => $size->getWidth(), 'mime' => $file->getContentType()]; } else { $response = ['status' => '0', 'error' => 'Error while uploading file', 'code' => 500]; } $this->sendJson($response); }