file size (M, K, G, T) to bytes (PHP)

function bytes($s) {
 $units = 'KMGT';
 return pow(1024, strpos($units, strpbrk($s, $units)) + 1) * (int) $s;
}
 
// usage:
echo bytes('1K'); // 1024
echo bytes('1M'); // 1048576

дядь Саша

hardcore javascript & php programmer, passionate reverse engineer

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.