資料整理,具體出處未知~
<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教學有興趣的朋友有幫助。