iBlog random » size http://blog.zurka.us Just another WordPress weblog Tue, 28 May 2013 20:28:47 +0000 en-US hourly 1 http://wordpress.org/?v=3.6 Format file sizes with PHP http://blog.zurka.us/format-file-sizes-with-php/ http://blog.zurka.us/format-file-sizes-with-php/#comments Wed, 29 Oct 2008 11:55:16 +0000 nasal http://blog.zurka.us/?p=634

A simple script that formats the number ob bytes of a file to kb, mb, gb or tb.

function mksize($bytes)
{
	if ($bytes < 1000 * 1024)
		return number_format($bytes / 1024, 2) . " KB";
	elseif ($bytes < 1000 * 1048576)
		return number_format($bytes / 1048576, 2) . " MB";
	elseif ($bytes < 1000 * 1073741824)
		return number_format($bytes / 1073741824, 2) . " GB";
	else
		return number_format($bytes / 1099511627776, 2) . " TB";
}
]]>
http://blog.zurka.us/format-file-sizes-with-php/feed/ 0