codeinc / human-readable-file-size
Human readable file size
Installs: 20 514
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=7.4
- ext-intl: *
This package is auto-updated.
Last update: 2024-11-21 19:04:22 UTC
README
This PHP 7 library, strongly inspired by Jeffrey Sambells' blog post, computes a size in bytes in a human readable form.
Installation
This library is available through Packagist and can be installed using Composer:
composer require codeinc/human-readable-file-size
Usage
Simple usage
<?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
Full configuration usage
<?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
License
This library is published under the MIT license (see the LICENSE file).