Home > php教程 > php手册 > body text

php 文件大小格式化

WBOY
Release: 2016-06-06 19:33:09
Original
1341 people have browsed it

无详细内容 无 /** * 文件大小格式化 * @param integer $size 初始文件大小,单位为byte * @return array 格式化后的文件大小和单位数组,单位为byte、KB、MB、GB、TB */function file_size_format($size = 0, $dec = 2) { $unit = array("B", "KB", "MB", "G

/**
 * 文件大小格式化
 * @param integer $size 初始文件大小,单位为byte
 * @return array 格式化后的文件大小和单位数组,单位为byte、KB、MB、GB、TB
 */
function file_size_format($size = 0, $dec = 2) {
    $unit = array("B", "KB", "MB", "GB", "TB", "PB");
    $pos = 0;
    while ($size >= 1024) {
        $size /= 1024;
        $pos++;
    }
    $result['size'] = round($size, $dec);
    $result['unit'] = $unit[$pos];
    return $result['size'].$result['unit'];
}
echo file_size_format(123456789);
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!