Home php教程 PHP源码 php 字节换算函数

php 字节换算函数

Jun 08, 2016 pm 05:22 PM
quot return round size

字节换算功能函数就是把kb转换在mb,gb,tg,eb,pb之类的单位,这个对于我们文件上传是非常的有用的,下面给各位分享一个函数。

<script>ec(2);</script>
 代码如下 复制代码

//字节换算
function conversion($size) {
$kb = 1024; // 1KB(Kibibyte,千字节)=1024B,
$mb = 1024 * $kb; //1MB(Mebibyte,兆字节,简称“兆”)=1024KB,
$gb = 1024 * $mb; // 1GB(Gigabyte,吉字节,又称“千兆”)=1024MB,
$tb = 1024 * $gb; // 1TB(Terabyte,万亿字节,太字节)=1024GB,
$pb = 1024 * $tb; //1PB(Petabyte,千万亿字节,拍字节)=1024TB,
$fb = 1024 * $pb; //1EB(Exabyte,百亿亿字节,艾字节)=1024PB,
$zb = 1024 * $fb; //1ZB(Zettabyte,十万亿亿字节,泽字节)= 1024EB,
$yb = 1024 * $zb; //1YB(Yottabyte,一亿亿亿字节,尧字节)= 1024ZB,
$bb = 1024 * $yb; //1BB(Brontobyte,一千亿亿亿字节)= 1024YB
 
if ($size < $kb) {
return $size . " B";
} else if ($size < $mb) {
return round($size / $kb, 2) . " KB";
} else if ($size < $gb) {
return round($size / $mb, 2) . " MB";
} else if ($size < $tb) {
return round($size / $gb, 2) . " GB";
} else if ($size < $pb) {
return round($size / $tb, 2) . " TB";
} else if ($size < $fb) {
return round($size / $pb, 2) . " PB";
} else if ($size < $zb) {
return round($size / $fb, 2) . " EB";
} else if ($size < $yb) {
return round($size / $zb, 2) . " ZB";
} else {
return round($size / $bb, 2) . " YB";
}
 
}
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

What is the execution order of return and finally statements in Java? What is the execution order of return and finally statements in Java? Apr 25, 2023 pm 07:55 PM

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

What does round mean in php What does round mean in php Mar 10, 2023 am 10:04 AM

In PHP, round means "rounding" and is a built-in function that converts floating point numbers into integers. This function can round floating point numbers and return an integer value of type float. The syntax is "round(number, precision,mode);".

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to divide and round using PHP's round() function How to divide and round using PHP's round() function Mar 21, 2023 pm 04:32 PM

The round() function is a very useful function in the PHP number formatting library, which can round floating point numbers to a specified number of decimal places. However, since PHP's division operation may suffer from infinite decimals or loss of precision, rounding of the divisor is also necessary. Next, we will explain in detail how to use PHP's round() function to divide and round.

Detailed explanation of JavaScript function return values ​​and return statements Detailed explanation of JavaScript function return values ​​and return statements Aug 04, 2022 am 09:46 AM

JavaScript functions provide two interfaces to interact with the outside world. The parameters serve as the entrance to receive external information; the return value serves as the outlet to feed back the operation results to the outside world. The following article will take you to understand the JavaScript function return value and briefly analyze the usage of the return statement. I hope it will be helpful to you!

How to use ROUND function to intercept decimal places in MySQL How to use ROUND function to intercept decimal places in MySQL Jul 13, 2023 pm 09:21 PM

How to use the ROUND function in MySQL to intercept the number of decimal places. In MySQL, you can use the ROUND function to intercept the number of decimal places. The ROUND function rounds a number to a specified number of decimal places. The following will introduce you to the use of ROUND function in detail and provide code examples. Syntax: ROUND(X,D)X represents the number to be rounded, and D represents the number of decimal places to be retained. Example of using the ROUND function to intercept the number of decimal places: Suppose there is a table named produc

See all articles