Php byte conversion function

Source: Internet
Author: User
The code is as follows: Copy code

// Byte Conversion
Function conversion ($ size ){
$ Kb = 1024; // 1KB (Kibibyte, kilobytes) = 1024B,
$ Mb = 1024 * $ kb; // 1 MB (Mebibyte, mb, or "MB") = 1024KB,
$ Gb = 1024 * $ mb; // 1 GB (Gigabyte, Jilin byte, also known as "gigabit") = 1024 MB,
$ Tb = 1024 * $ gb; // 1 TB (Terabyte, trillion bytes, too byte) = 1024 GB,
$ Pb = 1024 * $ tb; // 1 pb (Petabyte, trillion bytes, byte) = 1024 TB,
$ Fb = 1024 * $ pb; // 1EB (Exabyte, million bytes,) = pb,
$ Zb = 1024 * $ fb; // 1ZB (Zettabyte, 100,000 billion bytes, Ze Bytes) = 1024EB,
$ Yb = 1024 * $ zb; // 1YB (Yottabyte, 0.1 billion,) = 1024ZB,
$ Bb = 1024 * $ yb; // 1BB (Brontobyte, 100 billion Bytes) = 1024YB
 
If ($ size & lt; $ kb ){
Return $ size. "B ";
} Else if ($ size & lt; $ mb ){
Return round ($ size/$ kb, 2). "KB ";
} Else if ($ size & lt; $ gb ){
Return round ($ size/$ mb, 2). "MB ";
} Else if ($ size & lt; $ tb ){
Return round ($ size/$ gb, 2). "GB ";
} Else if ($ size & lt; $ pb ){
Return round ($ size/$ tb, 2). "TB ";
} Else if ($ size & lt; $ fb ){
Return round ($ size/$ pb, 2). "PB ";
} Else if ($ size & lt; $ zb ){
Return round ($ size/$ fb, 2). "EB ";
} Else if ($ size & lt; $ yb ){
Return round ($ size/$ zb, 2). "ZB ";
} Else {
Return round ($ size/$ bb, 2). "YB ";
}
 
}
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.