PHP使用適合閱讀的格式顯示文件大小的方法
更新時間:2015年03月05日 10:34:57 作者:紅薯
這篇文章主要介紹了PHP使用適合閱讀的格式顯示文件大小的方法,實(shí)例分析了php實(shí)現(xiàn)數(shù)據(jù)轉(zhuǎn)換的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實(shí)例講述了PHP使用適合閱讀的格式顯示文件大小的方法。分享給大家供大家參考。具體分析如下:
文件大小顯示,例如 1.7K , 2.9M
代碼如下:
復(fù)制代碼 代碼如下:
// 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程序設(shè)計有所幫助。
相關(guān)文章
php preg_match_all結(jié)合str_replace替換內(nèi)容中所有img
最近做站的時候,采集了大量的數(shù)據(jù),但采回來的數(shù)據(jù)基本上都要經(jīng)過過濾原站保留的數(shù)據(jù),其中IMG就是一個地方。網(wǎng)站上好多這些應(yīng)用例子似乎沒有必要“秀”出來,但站已幾天沒寫日志,那就來一個吧2008-10-10php簡單解析mysqli查詢結(jié)果的方法(2種方法)
這篇文章主要介紹了php簡單解析mysqli查詢結(jié)果的方法,結(jié)合實(shí)例形式簡單列舉了查詢結(jié)果存入對象與數(shù)組的兩種實(shí)現(xiàn)方法,需要的朋友可以參考下2016-06-06PHP使用mysql_fetch_object從查詢結(jié)果中獲取對象集的方法
這篇文章主要介紹了PHP使用mysql_fetch_object從查詢結(jié)果中獲取對象集的方法,實(shí)例分析了php操作mysql_fetch_object查詢數(shù)據(jù)庫的技巧,非常具有實(shí)用價值,需要的朋友可以參考下2015-03-03php SQLite學(xué)習(xí)筆記與常見問題分析
php SQLite學(xué)習(xí)資料收集,與一些常見問題的解決方法2008-07-07