PHP - format bytes to kilobytes, megabytes, gigabytes
Posted
by pygorex1
on Stack Overflow
See other posts from Stack Overflow
or by pygorex1
Published on 2010-03-24T18:34:55Z
Indexed on
2010/03/24
18:43 UTC
Read the original article
Hit count: 658
php
Scenario: the size of various files are stored in a database as bytes. What's the best way to format this size info to kilobytes, megabytes and gigabytes? For instance I have an MP3 that Ubuntu displays as "5.2 MB (5445632 bytes)". How would I display this on a web page as "5.2 MB" AND have files less than one megabyte display as KB and files one gigabyte and above display as GB?
© Stack Overflow or respective owner