Home  >  Article  >  Backend Development  >  Two ways to get file size in php

Two ways to get file size in php

WBOY
WBOYOriginal
2016-07-25 08:54:031340browse
  1. static function convert($size) {
  2. $unit=array('b','kb','mb','gb','tb','pb');
  3. return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
  4. }
Copy code

2, Method 2 of getting file size in php

  1. /**
  2. * Returns a human readable filesize
  3. */
  4. function HumanReadableFilesize($size) {
  5. $mod = 1024;
  6. $units = explode(' ','B KB MB GB TB PB' );
  7. for ($i = 0; $size > $mod; $i++) {
  8. $size /= $mod;
  9. }
  10. return round($size, 2) . ' ' . $units[$i] ;
  11. }
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