function get_bytes($size, $datasize) {
$types = array("B", "KB", "MB", "GB", "TB", "PB");
if ($key = array_search($datasize, $types))
return $size * pow(1024, $key);
else return "invalid type";
}
echo "7 MB = " . number_format(get_bytes(7, "MB"), 0, ',') . " bytes \n";
echo "3 KB = " . number_format(get_bytes(3, "KB"), 0, ',') . " bytes \n";
echo "1 GB = " . number_format(get_bytes(1, "GB"), 0, ',') . " bytes \n";
echo "2 TB = " . number_format(get_bytes(2, "TB"), 0, ',') . " bytes \n";
echo get_bytes(4, "XB");
/*
run:
7 MB = 7,340,032 bytes
3 KB = 3,072 bytes
1 GB = 1,073,741,824 bytes
2 TB = 2,199,023,255,552 bytes
invalid type
*/