diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-09-16 21:32:22 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-09-16 21:38:38 -0400 |
commit | 62fd225cfb17129c74ca3aaa6a75ddffe6453a3f (patch) | |
tree | f09c676d5b3477a71c0b85f9d4f1625bf9a9e192 /app/Controller/File.php | |
parent | 8bc141a286c23e2d3581bbfb49032cb80f4b35f3 (diff) |
Add abstract storage layer
Diffstat (limited to 'app/Controller/File.php')
-rw-r--r-- | app/Controller/File.php | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/app/Controller/File.php b/app/Controller/File.php index f73a9de9..7b7c75ee 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -60,7 +60,7 @@ class File extends Base { $task = $this->getTask(); - if (! $this->file->upload($task['project_id'], $task['id'], 'files')) { + if (! $this->file->uploadFiles($task['project_id'], $task['id'], 'files')) { $this->session->flashError(t('Unable to upload the file.')); } @@ -76,14 +76,13 @@ class File extends Base { $task = $this->getTask(); $file = $this->file->getById($this->request->getIntegerParam('file_id')); - $filename = FILES_DIR.$file['path']; - if ($file['task_id'] == $task['id'] && file_exists($filename)) { - $this->response->forceDownload($file['name']); - $this->response->binary(file_get_contents($filename)); + if ($file['task_id'] != $task['id']) { + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + $this->response->forceDownload($file['name']); + $this->objectStorage->passthru($file['path']); } /** @@ -113,16 +112,13 @@ class File extends Base { $task = $this->getTask(); $file = $this->file->getById($this->request->getIntegerParam('file_id')); - $filename = FILES_DIR.$file['path']; - - if ($file['task_id'] == $task['id'] && file_exists($filename)) { - $metadata = getimagesize($filename); - if (isset($metadata['mime'])) { - $this->response->contentType($metadata['mime']); - readfile($filename); - } + if ($file['task_id'] != $task['id']) { + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } + + $this->response->contentType($this->file->getImageMimeType($file['name'])); + $this->objectStorage->passthru($file['path']); } /** @@ -134,17 +130,13 @@ class File extends Base { $task = $this->getTask(); $file = $this->file->getById($this->request->getIntegerParam('file_id')); - $filename = FILES_DIR.$file['path']; - - if ($file['task_id'] == $task['id'] && file_exists($filename)) { - $this->response->contentType('image/jpeg'); - $this->file->generateThumbnail( - $filename, - $this->request->getIntegerParam('width'), - $this->request->getIntegerParam('height') - ); + if ($file['task_id'] != $task['id']) { + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } + + $this->response->contentType('image/jpeg'); + $this->objectStorage->passthru($this->file->getThumbnailPath($file['path'])); } /** |