/ Published in: PHP
Takes a number in bytes and returns the number in (KB,MB,GB) for human-readable format.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function ByteSize($bytes) { $size = $bytes / 1024; if($size < 1024) { $size .= ' KB'; } else { if($size / 1024 < 1024) { $size .= ' MB'; } else if ($size / 1024 / 1024 < 1024) { $size .= ' GB'; } } return $size; } // Returns '19.28mb' print ByteSize('20211982'); ?>