The Byte conversion function is used to convert kb to mb, gb, tg, eb, pb and other units. This function is very useful for file uploading. We will share with you a function below. The Byte conversion function is used to convert kb to mb, gb, tg, eb, pb and other units. This function is very useful for file uploading. We will share with you a function below.
Script ec (2); script
The Code is as follows: |
|
// 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 <$ 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 "; } } |