1function toByteSize($p_sFormatted) {
2 $aUnits = array('B'=>0, 'KB'=>1, 'MB'=>2, 'GB'=>3, 'TB'=>4, 'PB'=>5, 'EB'=>6, 'ZB'=>7, 'YB'=>8);
3 $sUnit = strtoupper(trim(substr($p_sFormatted, -2)));
4 if (intval($sUnit) !== 0) {
5 $sUnit = 'B';
6 }
7 if (!in_array($sUnit, array_keys($aUnits))) {
8 return false;
9 }
10 $iUnits = trim(substr($p_sFormatted, 0, strlen($p_sFormatted) - 2));
11 if (!intval($iUnits) == $iUnits) {
12 return false;
13 }
14 return $iUnits * pow(1024, $aUnits[$sUnit]);
15}
1<?php
2 function tobytes($size, $type)
3 {
4 $types = array("B", "KB", "MB", "GB", "TB", "PB"); //You can add the rest if needed..
5
6 if($key = array_search($type, $types))
7 return $size * pow(1024, $key);
8 else return "invalid type";
9 }
10
11 echo tobytes(15, "MB"); //15728640
12 echo tobytes(2, "KB"); //2048
13 echo tobytes(3, "w/e"); //invalid type
14?>
15