Home >Backend Development >PHP Tutorial >PHP get file size and format
Compilation of information, the specific source is unknown~
<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>
Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.
The above introduces PHP to obtain the file size and format it, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.