diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-05-25 15:15:59 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-05-25 15:15:59 -0400 |
commit | 60a45dbb685eb3b810dcced4820afe9d1f1ffe2d (patch) | |
tree | 0e098f3730730b017907eaa55494543244e027fe | |
parent | f9753e91d288c4d87d6a83ffe994d312eae5a3fd (diff) |
Improve file upload
-rw-r--r-- | app/Controller/File.php | 11 | ||||
-rw-r--r-- | app/Locales/de_DE/translations.php | 2 | ||||
-rw-r--r-- | app/Locales/es_ES/translations.php | 2 | ||||
-rw-r--r-- | app/Locales/fr_FR/translations.php | 2 | ||||
-rw-r--r-- | app/Locales/pl_PL/translations.php | 2 | ||||
-rw-r--r-- | app/Locales/pt_BR/translations.php | 2 | ||||
-rw-r--r-- | app/Model/File.php | 2 | ||||
-rw-r--r-- | app/Templates/file_new.php | 1 |
8 files changed, 21 insertions, 3 deletions
diff --git a/app/Controller/File.php b/app/Controller/File.php index 1604ab13..38cb82ab 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -24,6 +24,7 @@ class File extends Base $this->response->html($this->taskLayout('file_new', array( 'task' => $task, 'menu' => 'tasks', + 'max_size' => ini_get('upload_max_filesize'), 'title' => t('Attach a document') ))); } @@ -36,8 +37,14 @@ class File extends Base public function save() { $task = $this->getTask(); - $this->file->upload($task['project_id'], $task['id'], 'files'); - $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'#attachments'); + + if ($this->file->upload($task['project_id'], $task['id'], 'files') === true) { + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'#attachments'); + } + else { + $this->session->flashError(t('Unable to upload the file.')); + $this->response->redirect('?controller=file&action=create&task_id='.$task['id']); + } } /** diff --git a/app/Locales/de_DE/translations.php b/app/Locales/de_DE/translations.php index b554b01d..3816a251 100644 --- a/app/Locales/de_DE/translations.php +++ b/app/Locales/de_DE/translations.php @@ -371,4 +371,6 @@ return array( // 'Unable to update your sub-task.' => '', // 'Unable to create your sub-task.' => '', // 'Sub-task added successfully.' => '', + // 'Maximum size: ' => '', + // 'Unable to upload the file.' => '', ); diff --git a/app/Locales/es_ES/translations.php b/app/Locales/es_ES/translations.php index 0d8384dd..35ce6c05 100644 --- a/app/Locales/es_ES/translations.php +++ b/app/Locales/es_ES/translations.php @@ -369,4 +369,6 @@ return array( // 'Unable to update your sub-task.' => '', // 'Unable to create your sub-task.' => '', // 'Sub-task added successfully.' => '', + // 'Maximum size: ' => '', + // 'Unable to upload the file.' => '', ); diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php index 56acbed5..bc9b555f 100644 --- a/app/Locales/fr_FR/translations.php +++ b/app/Locales/fr_FR/translations.php @@ -369,4 +369,6 @@ return array( 'Unable to update your sub-task.' => 'Impossible de mettre à jour votre sous-tâche.', 'Unable to create your sub-task.' => 'Impossible de créer votre sous-tâche.', 'Sub-task added successfully.' => 'Sous-tâche ajouté avec succès.', + 'Maximum size: ' => 'Taille maximum : ', + 'Unable to upload the file.' => 'Impossible de transférer le fichier.', ); diff --git a/app/Locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php index dca01a2c..21b3e5a5 100644 --- a/app/Locales/pl_PL/translations.php +++ b/app/Locales/pl_PL/translations.php @@ -374,4 +374,6 @@ return array( // 'Unable to update your sub-task.' => '', // 'Unable to create your sub-task.' => '', // 'Sub-task added successfully.' => '', + // 'Maximum size: ' => '', + // 'Unable to upload the file.' => '', ); diff --git a/app/Locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php index 00fcccef..9939a0c3 100644 --- a/app/Locales/pt_BR/translations.php +++ b/app/Locales/pt_BR/translations.php @@ -370,4 +370,6 @@ return array( // 'Unable to update your sub-task.' => '', // 'Unable to create your sub-task.' => '', // 'Sub-task added successfully.' => '', + // 'Maximum size: ' => '', + // 'Unable to upload the file.' => '', ); diff --git a/app/Model/File.php b/app/Model/File.php index 41ecfba1..70b87b1b 100644 --- a/app/Model/File.php +++ b/app/Model/File.php @@ -159,7 +159,7 @@ class File extends Base if (@move_uploaded_file($uploaded_filename, self::BASE_PATH.$destination_filename)) { - $this->create( + return $this->create( $task_id, $original_filename, $destination_filename, diff --git a/app/Templates/file_new.php b/app/Templates/file_new.php index 43223d0c..643f340d 100644 --- a/app/Templates/file_new.php +++ b/app/Templates/file_new.php @@ -4,6 +4,7 @@ <form action="?controller=file&action=save&task_id=<?= $task['id'] ?>" method="post" enctype="multipart/form-data"> <input type="file" name="files[]" multiple /> + <div class="form-help"><?= t('Maximum size: ') ?><?= is_integer($max_size) ? Helper\format_bytes($max_size) : $max_size ?></div> <div class="form-actions"> <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/> <?= t('or') ?> |