diff --git a/include/class.format.php b/include/class.format.php index 074ac6adf8c0b6e60c2ce7ef5b87a2a9c6487749..5146c251e6b46e8d79ddab178b5480d611780342 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 fa962125a5a619dc106b4de013bc33051a1fc108..c1de7869ee5a4d60d3101ac4aaf718ca7f189168 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>