Home >Backend Development >PHP Tutorial >File size format conversion

File size format conversion

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:47:501450browse
Convert file bytes B to KB, MB, GB, TB
  1. function format_bytes($size,$r) {
  2. $units = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB ", "YB");
  3. for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
  4. return round($size,$r).$units [$i];
  5. }
  6. //$r is the number of decimal places
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn