Home > Backend Development > PHP Tutorial > PHP method to display file size in a format suitable for reading, _PHP Tutorial

PHP method to display file size in a format suitable for reading, _PHP Tutorial

WBOY
Release: 2016-07-13 10:05:25
Original
919 people have browsed it

PHP uses a format suitable for reading to display the file size.

This article describes the example of PHP using a format suitable for reading. Share it with everyone for your reference. The specific analysis is as follows:

File size display, such as 1.7K, 2.9M
The code is as follows:
Copy code The code is as follows: :// A much better and accurate version can be found
// in Aidan's PHP Repository:
// http://aidanlister.com/repos/v/function.size_readable.php
/**
 * Returns a human readable filesize
 *
 * @author      wesman20 (php.net)
 * @author      Jonas John
 * @version     0.3
 * @link        http://www.jonasjohn.de/snippets/php/readable-filesize.htm
 */
function HumanReadableFilesize($size) {
// Adapted from: http://www.php.net/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
          $size /= $mod;
}
Return round($size, 2) . ' ' . $units[$i];
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963845.htmlTechArticlePHP uses a format suitable for reading to display the file size. This article describes an example of PHP using a format suitable for reading. size method. Share it with everyone for your reference. Specific points...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template