Home >php教程 >php手册 >php如何获取文件大小

php如何获取文件大小

WBOY
WBOYOriginal
2016-06-13 09:41:23841browse


代码:

<span static</span> <span function</span> convert(<span $size</span><span ) { 
</span><span $unit</span>=<span array</span>('b','kb','mb','gb','tb','pb'<span ); 
</span><span return</span> @<span round</span>(<span $size</span>/<span pow</span>(1024,(<span $i</span>=<span floor</span>(<span log</span>(<span $size</span>,1024)))),2).' '.<span $unit</span>[<span $i</span><span ]; 
}</span>

<span /*</span><span *
* Returns a human readable filesize
</span><span */</span> by www.jbxue.<span com
</span><span function</span> HumanReadableFilesize(<span $size</span><span ) {
</span><span $mod</span> = 1024<span ; 
</span><span $units</span> = <span explode</span>(' ','B KB MB GB TB PB'<span );
</span><span for</span> (<span $i</span> = 0; <span $size</span> > <span $mod</span>; <span $i</span>++<span ) {
</span><span $size</span> /= <span $mod</span><span ;
}
</span><span return</span> <span round</span>(<span $size</span>, 2) . ' ' . <span $units</span>[<span $i</span><span ];
}</span>
Statement:
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