|
 |
|
13958 bytes จะเปลี่ยนให้เป็น kb ยังไงคับ 13958 bytes จะเปลี่ยนให้เป็น kb ยังไงคับขอบพระคุณมากคับ |
|
 |
|
|
 |
 |
|
round((13958 / 1024), 2);
|
 |
 |
 |
 |
Date :
2009-08-26 04:50:27 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
class tools {
/**
*
* easy file size รับค่าไบท์แล้วแปลงออกมาเป็นหน่วยต่างๆ เช่น KB, MB, GB, TB
* การใช้งาน เช่น tools::easyfilesize("51200");
*
**/
static public function easyfilesize($inputfilesize, $unitoutput = '') {
if ($inputfilesize <= 1024) {
$output = $inputfilesize." ".language::trans("Byte");
} elseif ($inputfilesize <= 1048576) {
$output = number_format($inputfilesize/'1024',2)." ".language::trans("KB");
} elseif ($inputfilesize <= 1073741824) {
$output = number_format($inputfilesize/'1048576',2)." ".language::trans("MB");
} elseif ($inputfilesize <= 1099511627776) {
$output = number_format($inputfilesize/'1073741824',2)." ".language::trans("GB");
} elseif ($inputfilesize <= 1125899906842624) {
$output = number_format($inputfilesize/'1099511627776',2)." ".language::trans("TB");
} elseif ($inputfilesize <= 1152921504606846976) {
$output = number_format($inputfilesize/'1125899906842624',2)." ".language::trans("PB");
} elseif ($inputfilesize <= 1180591620717411303424) {
$output = number_format($inputfilesize/'1152921504606846976',2)." ".language::trans("EB");
} else {
$output = number_format($inputfilesize/'1180591620717411303424',2)." ".language::trans("ZB");
}
$output = str_replace(".00", "", $output);
return $output;
}/*easyfilesize*/
}
?>
เวลาใช้งานก็ tools::easyfilesize("13958");
ถ้าไม่ต้องการตัดหน่วยทศนิยม .00 ออกก็ลบบรรทัดนี้ออกไป
$output = str_replace(".00", "", $output);
|
 |
 |
 |
 |
Date :
2009-08-26 05:05:04 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะลอง นำไปใช้
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-08-26 08:34:56 |
By :
vikikia |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบพระคุณมากมายคับ ใช้ได้แล้ว...
|
 |
 |
 |
 |
Date :
2009-08-26 14:20:55 |
By :
tcc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|