Changeset View
Changeset View
Standalone View
Standalone View
src/utils/viewutils.php
Context not available. | |||||
*/ | */ | ||||
function phutil_parse_bytes($input) { | function phutil_parse_bytes($input) { | ||||
$bytes = trim($input); | $bytes = trim($input); | ||||
if (!strlen($bytes)) { | if (!@strlen($bytes)) { | ||||
return null; | return null; | ||||
} | } | ||||
Context not available. | |||||
$bytes = preg_replace('/[ ,]/', '', $bytes); | $bytes = preg_replace('/[ ,]/', '', $bytes); | ||||
$matches = null; | $matches = null; | ||||
if (!preg_match('/^(?:\d+(?:[.]\d+)?)([kmgtp]?)b?$/i', $bytes, $matches)) { | if (!@preg_match('/^(?:\d+(?:[.]\d+)?)([kmgtp]?)b?$/i', $bytes, $matches)) { | ||||
throw new Exception(pht("Unable to parse byte size '%s'!", $input)); | throw new Exception(pht("Unable to parse byte size '%s'!", $input)); | ||||
} | } | ||||
Context not available. | |||||
$bytes = (float)$bytes; | $bytes = (float)$bytes; | ||||
if ($matches[1]) { | if ($matches[1]) { | ||||
$bytes *= $scale[strtolower($matches[1])]; | $bytes *= $scale[@strtolower($matches[1])]; | ||||
} | } | ||||
return (int)$bytes; | return (int)$bytes; | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0