php 字节换算函数
字节换算功能函数就是把kb转换在mb,gb,tg,eb,pb之类的单位,这个对于我们文件上传是非常的有用的,下面给各位分享一个函数。
代码如下 | 复制代码 |
//字节换算 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"; } } |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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











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

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.

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

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.

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

Vue3.2 setup syntax sugar is a compile-time syntax sugar that uses the combined API in a single file component (SFC) to solve the cumbersome setup in Vue3.0. The declared variables, functions, and content introduced by import are exposed through return, so that they can be used in Vue3.0. Problems in use 1. There is no need to return declared variables, functions and content introduced by import during use. You can use syntactic sugar //import the content introduced import{getToday}from'./utils'//variable constmsg='Hello !'//function func

Usage of return in JavaScript requires specific code examples In JavaScript, the return statement is used to specify the value returned from a function. Not only can it be used to end the execution of a function, it can also return a value to the place where the function was called. The return statement has the following common uses: Return a value The return statement can be used to return a value to the place where the function is called. Here is a simple example: functionadd(a,b){
