字节换算功能函数就是把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

Dreamweaver Mac version
Visual web development tools

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
