3.134.118.95 |    

Navigation

Google Advertisement

This function convert the file size (Byte) in human readable format.

return_converted_size
  1. // echo return_converted_size ( '3063557' );
  2. // 2.92 MB
  3. //
  4. // *****************************************************************
  5. // This function convert the file size (Byte) in human readable format.
  6.  
  7. function return_converted_size ( $size ) {
  8.  
  9. // convert from Byte to KB...
  10. if ( $size > 1024 ) {
  11. 	(int) $size=(int)($size/1024);
  12. 	(string) $unit="KB";
  13. }
  14. // convert from KB to MB...
  15. if ( $size > 1024 ) {
  16. 	(float) $size=($size/1024);
  17. 	(string) $unit="MB";
  18. }
  19. // convert from MB to GB...
  20. if ( $size > 1024 ) {
  21. 	(float) $size=($size/1024);
  22. 	(string) $unit="GB";
  23. }
  24. // convert from GB to TB...
  25. if ( $size > 1024 ) {
  26. 	(float) $size=($size/1024);
  27. 	(string) $unit="TB";
  28. }
  29.  
  30. if ( $unit == "MB" ) (float) $size=sprintf( "%.2f", $size );
  31. if ( $unit == "GB" || $unit == "TB" ) (float) $size=sprintf( "%.1f", $size );
  32.  
  33. return $size." ".$unit;
  34.  
  35. }
Parsed in 0.010 seconds at 86.15 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 3 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)