


PHP method to display file size in a format suitable for reading_PHP Tutorial
Jul 13, 2016 am 10:04 AMPHP uses a format suitable for reading to display the file size
This article mainly introduces the method for PHP to use a format suitable for reading to display the file size, and analyzes the PHP implementation data with examples The conversion skills have certain reference value. Friends in need can refer to it
The example in this article describes how PHP displays the file size in 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:
The code is as follows:
// 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.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
