Home > Backend Development > PHP Tutorial > PHP get file size and format

PHP get file size and format

WBOY
Release: 2016-08-08 09:20:11
Original
1669 people have browsed it

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template