From 53ce5272ac2d902bea825c2464a5587824556f45 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 14 Nov 2013 17:40:58 -0600 Subject: [PATCH] Make max_upload_filesize a drop-down list --- include/class.format.php | 4 +-- include/staff/settings-tickets.inc.php | 35 +++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/class.format.php b/include/class.format.php index 074ac6adf..5146c251e 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -24,10 +24,10 @@ class Format { return $bytes; if($bytes<1024) return $bytes.' bytes'; - if($bytes <102400) + if($bytes < (900<<10)) return round(($bytes/1024),1).' kb'; - return round(($bytes/1024000),1).' mb'; + return round(($bytes/1048576),1).' mb'; } function file_name($filename) { diff --git a/include/staff/settings-tickets.inc.php b/include/staff/settings-tickets.inc.php index fa962125a..c1de7869e 100644 --- a/include/staff/settings-tickets.inc.php +++ b/include/staff/settings-tickets.inc.php @@ -198,9 +198,38 @@ if(!($maxfileuploads=ini_get('max_file_uploads'))) <tr> <td width="180">Maximum File Size:</td> <td> - <input type="text" name="max_file_size" value="<?php echo $config['max_file_size']; ?>"> in bytes. - <em>(System Max. <?php echo Format::file_size(ini_get('upload_max_filesize')); ?>)</em> - <font class="error"> <?php echo $errors['max_file_size']; ?></font> + <select name="max_file_size"> + <option value="262144">— Small —</option> + <?php $next = 512 << 10; + $max = strtoupper(ini_get('upload_max_filesize')); + $limit = (int) $max; + if (!$limit) $limit = 2 << 20; # 2M default value + elseif (strpos($max, 'K')) $limit <<= 10; + elseif (strpos($max, 'M')) $limit <<= 20; + elseif (strpos($max, 'G')) $limit <<= 30; + while ($next <= $limit) { + // Select the closest, larger value (in case the + // current value is between two) + $diff = $next - $config['max_file_size']; + $selected = ($diff >= 0 && $diff < $next / 2) + ? 'selected="selected"' : ''; ?> + <option value="<?php echo $next; ?>" <?php echo $selected; + ?>><?php echo Format::file_size($next); + ?></option><?php + $next *= 2; + } + // Add extra option if top-limit in php.ini doesn't fall + // at a power of two + if ($next < $limit * 2) { + $selected = ($limit == $config['max_file_size']) + ? 'selected="selected"' : ''; ?> + <option value="<?php echo $limit; ?>" <?php echo $selected; + ?>><?php echo Format::file_size($limit); + ?></option><?php + } + ?> + </select> + <font class="error"> <?php echo $errors['max_file_size']; ?></font> </td> </tr> <tr> -- GitLab