美文网首页
PHP 文件大小转换,byt转MB、GB、KB

PHP 文件大小转换,byt转MB、GB、KB

作者: 可乐_加冰_ | 来源:发表于2020-01-19 15:45 被阅读0次

function formatSizeUnits($bytes)

    {

        if ($bytes >= 1073741824)

        {

            $bytes = number_format($bytes / 1073741824, 2) . ' GB';

        }

        elseif ($bytes >= 1048576)

        {

            $bytes = number_format($bytes / 1048576, 2) . ' MB';

        }

        elseif ($bytes >= 1024)

        {

            $bytes = number_format($bytes / 1024, 2) . ' KB';

        }

        elseif ($bytes > 1)

        {

            $bytes = $bytes . ' bytes';

        }

        elseif ($bytes == 1)

        {

            $bytes = $bytes . ' byte';

        }

        else

        {

            $bytes = '0 bytes';

        }

        return $bytes;

相关文章

网友评论

      本文标题:PHP 文件大小转换,byt转MB、GB、KB

      本文链接:https://www.haomeiwen.com/subject/ubbrzctx.html