If Not True Then False

Format bytes with PHP – B, KB, MB, GB, TB, PB, EB, ZB, YB converter - Comment Page: 1

Simple PHP function that formats the bytes to the desired form. Possible unit options are: Byte (B) Kilobyte (KB) Megabyte (MB) Gigabyte (GB) Terabyte (TB) Petabyte (PB) Exabyte (EB) Zettabyte (ZB) Yottabyte (YB) Function takes three parameter: (bytes mandatory, unit optional, decimals optional) PHP byteFormat function for formatting bytes <?php function...
Tagged with:

17 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *

Input your comment.
help

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Input your name.

Oliver Nassar

Raaaddddd!
Thanks dude. Saved me a bunch of time.

I used this for formating bytes, btw:

/**
* filesize function.
*
* @access public
* @static
* @param mixed $size
* @param int $round. (default: 0)
* @return void
*/
// http://www.veign.com/code-view.php?type=web&codeid=74
public static function filesize($size, $round = 0) {
$sizes = array(‘b’, ‘kb’, ‘meg’, ‘gb’, ‘tb’, ‘pb’, ‘eb’, ‘zb’, ‘yb’);
for ($i=0; $size > 1024 && isset($sizes[$i+1]); $i++) $size /= 1024;
return round($size, $round).$sizes[$i];
}

reply Reply
Anonymous

Dr Garg? How strange that I should find your name on a random website. I guess we were both looking for the same kind of info. :)

reply Reply
Juan Manuel

Amazing!!, but in the examples, consider remove the \n concat, because the example becomes difficult to read… greetings from Argentina.

reply Reply
JR

Hi Juan,

Thanks, I removed \n from examples and yes, you are right, it’s easier to read.

reply Reply