首頁 >後端開發 >php教程 >PHP取得檔案大小並格式化

PHP取得檔案大小並格式化

WBOY
WBOY原創
2016-08-08 09:20:111670瀏覽

資料整理,具體出處未知~

<code><span><span>function</span><span>formatSize</span><span>(<span>$size</span>)</span> {</span><span>$sizes</span> = <span>array</span>(<span>" Bytes"</span>, <span>" KB"</span>, <span>" MB"</span>, <span>" GB"</span>, <span>" TB"</span>, <span>" PB"</span>, <span>" EB"</span>, <span>" ZB"</span>, <span>" YB"</span>); 
    <span>if</span> (<span>$size</span> == <span>0</span>) {  
        <span>return</span>(<span>'n/a'</span>);  
    } <span>else</span> { 
      <span>return</span> (round(<span>$size</span>/pow(<span>1024</span>, (<span>$i</span> = floor(log(<span>$size</span>, <span>1024</span>)))), <span>2</span>) . <span>$sizes</span>[<span>$i</span>]);  
    } 
} </code>

版權聲明:本文為博主原創文章,未經博主允許不得轉載。

以上就介紹了PHP取得檔案大小並格式化,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn