codeinc / human-readable-file-size
可读性文件大小
1.0.0
2020-01-31 13:37 UTC
Requires
- php: >=7.4
- ext-intl: *
This package is auto-updated.
Last update: 2024-09-21 18:42:02 UTC
README
此PHP 7库深受Jeffrey Sambells的博客文章启发,以可读形式计算字节数。
安装
此库可通过Packagist获得,并可以使用Composer安装。
composer require codeinc/human-readable-file-size
使用方法
简单使用
<?php use CodeInc\HumanReadableFileSize\HumanReadableFileSize; echo HumanReadableFileSize::getHumanSize(filesize('a-file.pdf')); // outputs 2.88MB echo HumanReadableFileSize::getHumanSize(filesize('a-file.pdf'), 1); // outputs 2.9MB echo HumanReadableFileSize::getHumanSize(filesize('a-file.pdf'), 0); // outputs 3MB
完整配置使用
<?php use CodeInc\HumanReadableFileSize\HumanReadableFileSize; $readableSize = new HumanReadableFileSize(); $readableSize->useNumberFormatter('fr-FR'); $readableSize->setSpaceBeforeUnit(); $readableSize->setByteSymbol('o'); echo $readableSize->compute(filesize('a-file.pdf'), 1); // outputs 2,9 Mo
许可协议
此库遵循MIT许可协议(请参阅LICENSE文件)。