From 7df0e352101c36d06e6831123be678a8a6b5077d Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 05 Sep 2009 03:47:07 -0400
Subject: [PATCH] - Check 'post_max_size' for upload max filesize (#1486089)

---
 CHANGELOG                          |    1 +
 program/steps/mail/attachments.inc |    8 +++++++-
 program/steps/mail/compose.inc     |    9 ++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 9d72a4a..8cdd04f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG RoundCube Webmail
 ===========================
 
+- Check 'post_max_size' for upload max filesize (#1486089) 
 - Password Plugin: Fix %d inserts username instead of domain (#1486088)
 - Fix rcube_mdb2::affected_rows() (#1486082)
 
diff --git a/program/steps/mail/attachments.inc b/program/steps/mail/attachments.inc
index 6015703..b57037d 100644
--- a/program/steps/mail/attachments.inc
+++ b/program/steps/mail/attachments.inc
@@ -128,7 +128,13 @@
   }
 }
 else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-  $OUTPUT->command('display_message', rcube_label('fileuploaderror'), 'error');
+  // if filesize exceeds post_max_size then $_FILES array is empty,
+  // show filesizeerror instead of fileuploaderror
+  if ($maxsize = ini_get('post_max_size'))
+    $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes($maxsize)))));
+  else
+    $msg = rcube_label('fileuploaderror');
+  $OUTPUT->command('display_message', $msg, 'error');
 }
 
 // send html page with JS calls as response
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 79a95db..5d1fe21 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -823,13 +823,20 @@
   // add ID if not given
   if (!$attrib['id'])
     $attrib['id'] = 'rcmUploadbox';
+
+  // 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;
+  $max_filesize = show_bytes($max_filesize);
   
   $button = new html_inputfield(array('type' => 'button', 'class' => 'button'));
   
   $out = html::div($attrib,
     $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data'),
       html::div(null, rcmail_compose_attachment_field(array())) .
-      html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))))) .
+      html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))) .
       html::div('buttons',
         $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) . ' ' .
         $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)"))

--
Gitblit v1.9.1