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

php如何获取文件大小

WBOY
发布: 2016-06-13 09:41:23
原创
850 人浏览过


代码:

<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>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板