Skip to content
Snippets Groups Projects
Commit 53ce5272 authored by Jared Hancock's avatar Jared Hancock
Browse files

Make max_upload_filesize a drop-down list

parent c21dac64
No related branches found
No related tags found
No related merge requests found
...@@ -24,10 +24,10 @@ class Format { ...@@ -24,10 +24,10 @@ class Format {
return $bytes; return $bytes;
if($bytes<1024) if($bytes<1024)
return $bytes.' bytes'; return $bytes.' bytes';
if($bytes <102400) if($bytes < (900<<10))
return round(($bytes/1024),1).' kb'; return round(($bytes/1024),1).' kb';
return round(($bytes/1024000),1).' mb'; return round(($bytes/1048576),1).' mb';
} }
function file_name($filename) { function file_name($filename) {
......
...@@ -198,9 +198,38 @@ if(!($maxfileuploads=ini_get('max_file_uploads'))) ...@@ -198,9 +198,38 @@ if(!($maxfileuploads=ini_get('max_file_uploads')))
<tr> <tr>
<td width="180">Maximum File Size:</td> <td width="180">Maximum File Size:</td>
<td> <td>
<input type="text" name="max_file_size" value="<?php echo $config['max_file_size']; ?>"> in bytes. <select name="max_file_size">
<em>(System Max. <?php echo Format::file_size(ini_get('upload_max_filesize')); ?>)</em> <option value="262144">&mdash; Small &mdash;</option>
<font class="error">&nbsp;<?php echo $errors['max_file_size']; ?></font> <?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">&nbsp;<?php echo $errors['max_file_size']; ?></font>
</td> </td>
</tr> </tr>
<tr> <tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment