PHP使用适合阅读的格式显示文件大小的方法
更新时间:2015年03月05日 10:34:57 作者:红薯
这篇文章主要介绍了PHP使用适合阅读的格式显示文件大小的方法,实例分析了php实现数据转换的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了PHP使用适合阅读的格式显示文件大小的方法。分享给大家供大家参考。具体分析如下:
文件大小显示,例如 1.7K , 2.9M
代码如下:
复制代码 代码如下:
// A much better and accurate version can be found
// in Aidan's PHP Repository:
// http://aidanlister.com/repos/v/function.size_readable.php
/**
* Returns a human readable filesize
*
* @author wesman20 (php.net)
* @author Jonas John
* @version 0.3
* @link http://www.jonasjohn.de/snippets/php/readable-filesize.htm
*/
function HumanReadableFilesize($size) {
// Adapted from: http://www.php.net/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
// in Aidan's PHP Repository:
// http://aidanlister.com/repos/v/function.size_readable.php
/**
* Returns a human readable filesize
*
* @author wesman20 (php.net)
* @author Jonas John
* @version 0.3
* @link http://www.jonasjohn.de/snippets/php/readable-filesize.htm
*/
function HumanReadableFilesize($size) {
// Adapted from: http://www.php.net/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
希望本文所述对大家的php程序设计有所帮助。
相关文章
php preg_match_all结合str_replace替换内容中所有img
最近做站的时候,采集了大量的数据,但采回来的数据基本上都要经过过滤原站保留的数据,其中IMG就是一个地方。网站上好多这些应用例子似乎没有必要“秀”出来,但站已几天没写日志,那就来一个吧2008-10-10PHP使用mysql_fetch_object从查询结果中获取对象集的方法
这篇文章主要介绍了PHP使用mysql_fetch_object从查询结果中获取对象集的方法,实例分析了php操作mysql_fetch_object查询数据库的技巧,非常具有实用价值,需要的朋友可以参考下2015-03-03
最新评论