diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-08-16 12:11:21 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-08-16 12:11:21 +0000 |
| commit | 9bee1c60a7f16d015c7fa01d4aeecb6c0362ee23 (patch) | |
| tree | 1ee52d6bfd5be805e638a56d943b4a3a5c6d96d3 /roundcubemail/program | |
| parent | 1edf2911b5d4f73dd1adae0f22b9122ad27fc218 (diff) | |
- Add client-side checking of uploaded files size
git-svn-id: https://svn.roundcube.net/trunk@5071 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program')
| -rw-r--r-- | roundcubemail/program/include/main.inc | 15 | ||||
| -rw-r--r-- | roundcubemail/program/js/app.js | 12 | ||||
| -rw-r--r-- | roundcubemail/program/steps/mail/compose.inc | 17 |
3 files changed, 29 insertions, 15 deletions
diff --git a/roundcubemail/program/include/main.inc b/roundcubemail/program/include/main.inc index d43f8ea50..a3edbf7ca 100644 --- a/roundcubemail/program/include/main.inc +++ b/roundcubemail/program/include/main.inc @@ -2332,7 +2332,7 @@ function rcube_upload_progress() $RCMAIL->output->send(); } -function rcube_upload_progress_init() +function rcube_upload_init() { global $RCMAIL; @@ -2343,6 +2343,19 @@ function rcube_upload_progress_init() $RCMAIL->output->set_env('upload_progress_time', (int) $seconds); } } + + // find max filesize value + $max_filesize = parse_bytes(ini_get('upload_max_filesize')); + $max_postsize = parse_bytes(ini_get('post_max_size')); + if ($max_postsize && $max_postsize < $max_filesize) + $max_filesize = $max_postsize; + + $RCMAIL->output->set_env('max_filesize', $max_filesize); + $max_filesize = show_bytes($max_filesize); + $RCMAIL->output->set_env('filesizeerror', rcube_label(array( + 'name' => 'filesizeerror', 'vars' => array('size' => $max_filesize)))); + + return $max_filesize; } /** diff --git a/roundcubemail/program/js/app.js b/roundcubemail/program/js/app.js index a4fa4194b..717b21cfe 100644 --- a/roundcubemail/program/js/app.js +++ b/roundcubemail/program/js/app.js @@ -3253,11 +3253,21 @@ function rcube_webmail() return false; // get file input field, count files on capable browser - var field = $('input[type=file]', form).get(0), + var i, size = 0, field = $('input[type=file]', form).get(0), files = field.files ? field.files.length : field.value ? 1 : 0; // create hidden iframe and post upload form if (files) { + // check file size + if (field.files && this.env.max_filesize && this.env.filesizeerror) { + for (i=0; i<files; i++) + size += field.files[i].size; + if (size && size > this.env.max_filesize) { + this.display_message(this.env.filesizeerror, 'error'); + return; + } + } + var frame_name = this.async_upload_form(form, 'upload', function(e) { var d, content = ''; try { diff --git a/roundcubemail/program/steps/mail/compose.inc b/roundcubemail/program/steps/mail/compose.inc index 31de0d9ee..9a94ff742 100644 --- a/roundcubemail/program/steps/mail/compose.inc +++ b/roundcubemail/program/steps/mail/compose.inc @@ -1206,20 +1206,11 @@ function rcmail_compose_attachment_form($attrib) if (!$attrib['id']) $attrib['id'] = 'rcmUploadbox'; - // Enable upload progress bar - rcube_upload_progress_init(); + // Get filesize, enable upload progress bar + $max_filesize = rcube_upload_init(); - // find max filesize value - $max_filesize = parse_bytes(ini_get('upload_max_filesize')); - $max_postsize = parse_bytes(ini_get('post_max_size')); - if ($max_postsize && $max_postsize < $max_filesize) - $max_filesize = $max_postsize; - - $OUTPUT->set_env('max_filesize', $max_filesize); - $max_filesize = show_bytes($max_filesize); - $button = new html_inputfield(array('type' => 'button')); - + $out = html::div($attrib, $OUTPUT->form_tag(array('name' => 'uploadform', 'method' => 'post', 'enctype' => 'multipart/form-data'), html::div(null, rcmail_compose_attachment_field(array('size' => $attrib['attachmentfieldsize']))) . @@ -1230,7 +1221,7 @@ function rcmail_compose_attachment_form($attrib) ) ) ); - + $OUTPUT->add_gui_object('uploadbox', $attrib['id']); return $out; } |
