php 位元組換算函數

來源:互聯網
上載者:User
 代碼如下 複製代碼

//位元組換算
function conversion($size) {
$kb = 1024; // 1KB(Kibibyte,KB)=1024B,
$mb = 1024 * $kb; //1MB(Mebibyte,MB,簡稱“兆”)=1024KB,
$gb = 1024 * $mb; // 1GB(Gigabyte,吉位元組,又稱“千兆”)=1024MB,
$tb = 1024 * $gb; // 1TB(Terabyte,萬億位元組,太位元組)=1024GB,
$pb = 1024 * $tb; //1PB(Petabyte,千萬億位元組,拍位元組)=1024TB,
$fb = 1024 * $pb; //1EB(Exabyte,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";
}
 
}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.