From 8936792f6f7a408dae7e0a6a41274202822acd9c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 16 Feb 2016 21:12:43 -0500 Subject: Add file attachements to projects --- app/Controller/FileViewer.php | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 app/Controller/FileViewer.php (limited to 'app/Controller/FileViewer.php') diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php new file mode 100644 index 00000000..24ccc691 --- /dev/null +++ b/app/Controller/FileViewer.php @@ -0,0 +1,89 @@ +getFile(); + $params = array('file_id' => $file['id'], 'project_id' => $this->request->getIntegerParam('project_id')); + + if ($file['model'] === 'taskFile') { + $params['task_id'] = $file['task_id']; + } + + $this->response->html($this->template->render('file_viewer/show', array( + 'file' => $file, + 'params' => $params, + ))); + } + + /** + * Display image + * + * @access public + */ + public function image() + { + try { + $file = $this->getFile(); + $this->response->contentType($this->helper->file->getImageMimeType($file['name'])); + $this->objectStorage->output($file['path']); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } + + /** + * Display image thumbnail + * + * @access public + */ + public function thumbnail() + { + $this->response->contentType('image/jpeg'); + + try { + $file = $this->getFile(); + $model = $file['model']; + $this->objectStorage->output($this->$model->getThumbnailPath($file['path'])); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + + // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 + $data = $this->objectStorage->get($file['path']); + $this->$model->generateThumbnailFromData($file['path'], $data); + $this->objectStorage->output($this->$model->getThumbnailPath($file['path'])); + } + } + + /** + * File download + * + * @access public + */ + public function download() + { + try { + $file = $this->getFile(); + $this->response->forceDownload($file['name']); + $this->objectStorage->output($file['path']); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } +} -- cgit v1.2.3