5/29/2019

PHP :: Function แปลง Bytes เป็น MB, GB, KB

PHP :: Function แปลง Bytes เป็น MB, GB, KB

  1.  
  2. function formatSizeUnits($bytes)
  3. {
  4.     if($bytes >= 1073741824){
  5.     $bytes = number_format($bytes / 1073741824, 2) . ' GB';
  6.    } elseif($bytes >= 1048576){
  7.       $bytes = number_format($bytes / 1048576, 2) . ' MB';
  8.    } elseif ($bytes >= 1024){
  9.       $bytes = number_format($bytes / 1024, 2) . ' KB';
  10.    } elseif ($bytes > 1){
  11.       $bytes = $bytes . ' bytes';
  12.    } elseif ($bytes == 1){
  13.       $bytes = $bytes . ' byte';
  14.    } else {
  15.       $bytes = '-';
  16.    }
  17. return $bytes;
  18. }//Close Functions.
  19.  


ตัวอย่าง
https://intranet.sci.com/sci/CheckServer/check_start.php

https://stackoverflow.com/questions/5501427/php-filesize-mb-kb-conversion/5501447

No comments:

Post a Comment