Snipe.Net Geeky, sweary things.

Displaying file sizes in human readable format

D

This code prints out “b” for bytes, “m” for megs, etc depending on the file size.

= 1073741824) {
		$fileweight = round($fileweight / 1073741824 * 100) / 100 . "GB";
	} elseif ($fileweight >= 1048576) {
		$fileweight = round($fileweight / 1048576 * 100) / 100 . "MG";
	} elseif ($fileweight >= 1024) {
		$fileweight = round($fileweight / 1024 * 100) / 100 . "k";
	} else {
		$fileweight = $fileweight . "b";
	}
	return $fileweight;
} // end function
?> 

About the author

snipe

I’m a tech geek/dev/infosec-nerd/scuba diver/blacksmith/sword-fighter/crime fighter/ENTP/warcrafter/activist. I run Grokability, Inc, and run several open source projects, including Snipe-IT Asset Management. Tweet at me @snipeyhead or read more

By snipe
Snipe.Net Geeky, sweary things.

About Me

I’m a tech geek/dev/infosec-nerd/scuba diver/blacksmith/sword-fighter/crime fighter/ENTP/warcrafter/activist. I run Grokability, Inc, and run several open source projects, including Snipe-IT Asset Management. Tweet at me @snipeyhead or read more

Get in Touch