From 738b6ae5832fb7c2992ec0dc52399e4dbf3d096d Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 13 Feb 2016 19:24:36 -0500 Subject: Add file drag and drop and asynchronous upload --- app/Controller/File.php | 2 +- app/Helper/Text.php | 23 +++++++++++++++++++++++ app/Template/file/new.php | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/Controller/File.php b/app/Controller/File.php index 50db3865..4ac45fbd 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -42,7 +42,7 @@ class File extends Base $this->response->html($this->helper->layout->task('file/new', array( 'task' => $task, - 'max_size' => ini_get('upload_max_filesize'), + 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), ))); } diff --git a/app/Helper/Text.php b/app/Helper/Text.php index 59bfd997..83f1e3f9 100644 --- a/app/Helper/Text.php +++ b/app/Helper/Text.php @@ -42,6 +42,29 @@ class Text extends Base return round(pow(1024, $base - floor($base)), $precision).$suffixes[(int)floor($base)]; } + /** + * Get the number of bytes from PHP size + * + * @param integer $val PHP size (example: 2M) + * @return integer + */ + public function phpToBytes($val) + { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + + switch ($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; + } + /** * Return true if needle is contained in the haystack * diff --git a/app/Template/file/new.php b/app/Template/file/new.php index 1702638d..e84ef839 100644 --- a/app/Template/file/new.php +++ b/app/Template/file/new.php @@ -1,14 +1,33 @@ + + + -
- form->csrf() ?> - -
text->bytes($max_size) : $max_size ?>
-
- - - url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> +
+
+
- \ No newline at end of file +
+ + + +
+ + + url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> +
-- cgit v1.2.3