1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 04:10:38 +02:00

Fix for file_size_decode() in PHP7.

This commit is contained in:
Cameron
2018-08-20 13:41:21 -07:00
parent 34a4f0ade8
commit 1f69d7cd0a
2 changed files with 29 additions and 23 deletions

View File

@@ -1692,19 +1692,19 @@ $text .= "
<table class='table table-striped table-bordered'> <table class='table table-striped table-bordered'>
<tr><th>".LAN_TYPE."</th><th>".UPLLAN_33."</th> <tr><th>".LAN_TYPE."</th><th>".UPLLAN_33."</th>
"; ";
$fl = e107::getFile(); $fl = e107::getFile();
$data = $fl->getFiletypeLimits(); $data = $fl->getAllowedFileTypes();
foreach($data as $k=>$v) foreach($data as $k=>$v)
{ {
$text .= "<tr><td>".$k."</td> $text .= "<tr><td>".$k."</td>
<td>".$fl->file_size_encode($v)."</td> <td>".$fl->file_size_encode($v)."</td>
</tr>"; </tr>";
} }
// $text .= print_a($data,true); // $text .= print_a($data,true);

View File

@@ -837,47 +837,53 @@ class e_file
* @param int $compare - a 'compare' value * @param int $compare - a 'compare' value
* @param string $action - values (gt|lt) * @param string $action - values (gt|lt)
* *
* @return int file size value. * @return int file size value in bytes.
* If the decoded value evaluates to zero, returns the value of $compare * If the decoded value evaluates to zero, returns the value of $compare
* If $action == 'gt', return the larger of the decoded value and $compare * If $action == 'gt', return the larger of the decoded value and $compare
* If $action == 'lt', return the smaller of the decoded value and $compare * If $action == 'lt', return the smaller of the decoded value and $compare
*/ */
function file_size_decode($source, $compare = 0, $action = '') function file_size_decode($source, $compare = 0, $action = '')
{ {
$source = trim($source); $source = trim($source);
if (strtolower(substr($source, -1, 1)) == 'b') $source = strtoupper($source);
$source = substr($source, 0, -1); // Trim a trailing byte indicator
//$mult = 1; list($val, $unit) = preg_split('#(?<=\d)(?=[a-z])#i', $source);
if (strlen($source) && (strtoupper(substr($source, -1, 1)) == 'B'))
$source = substr($source, 0, -1); $val = (int) $val;
if (!$source || is_numeric($source))
if(!$source || is_numeric($source))
{ {
$val = $source; $val = (int) $source;
} }
else else
{ {
$val = substr($source, 0, -1); switch($unit)
switch (substr($source, -1, 1))
{ {
case 'T': case 'T':
$val = $val * 1024; case 'TB':
$val = $val * 1024 * 1024 * 1024 * 1024;
break; break;
case 'G': case 'G':
$val = $val * 1024; case 'GB':
$val = $val * 1024 * 1024 * 1024;
break; break;
case 'M': case 'M':
$val = $val * 1024; case 'MB':
$val = $val * 1024 * 1024;
break; break;
case 'K': case 'K':
case 'k': case 'KB':
$val = $val * 1024; $val = $val * 1024;
break; break;
} }
} }
if ($val == 0) if($val == 0)
{
return $compare; return $compare;
}
switch ($action) switch($action)
{ {
case 'lt': case 'lt':
return min($val, $compare); return min($val, $compare);
@@ -886,7 +892,7 @@ class e_file
default: default:
return $val; return $val;
} }
// return 0; // return 0;
} }
/** /**