PHP Classes
elePHPant
Icontem

PHP Human Readable File Size: Convert the size of a file to a readable format

Recommend this page to a friend!

  Author Author  
Name: Rafal Janisz <contact>
Classes: 2 packages by
Country: Poland Poland


  Detailed description   Download Download .zip .tar.gz  
This package can convert the size of a file to a readable format.

It takes a string that contains a number of bytes of size of a given file and returns a string that represents that number in a more human readable format using suffixes for KB, MB, TB, etc..

The package allows configuring the number of decimal digits to be used as precision when rounding the number to be formatted.

Details

readablesize

Build Status codecov

Converts number of bytes to human readable number by taking the number of that unit that the bytes will go into it.

Requirements

  • PHP >= 7.1
  • (optional) PHPUnit to run tests.

Install

Via Composer:

$ composer require ravjanisz/readablesize

Usage

// add settings instance
use Rav\Size\SizeSettings;
// add instance
use Rav\Size\Size;

//base for calculation can be added as SizeSettings constructor parameter
//SizeSettings::BINARY or SizeSettings::DECIMAL
$settings = new SizeSettings();
//set precision for size
$settings->setPrecision(2);

//new object instance
$this->size = new Size($settings);

//return '1.46KiB'
echo $this->size->human('1500');

//convert size
//return '0.01TiB'
echo $this->size->convert(Size::MB, Size::TB, '9500');

Documentation

None

Support the development

Do you like this project? Support it by donating

<a href="https://www.buymeacoffee.com/ravjanisz">

alt Buy me a coffee

</a>

License

readablesize is licensed under the MIT License - see the LICENSE file for details


  Classes of Rafal Janisz  >  PHP Human Readable File Size  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  

 

Name: PHP Human Readable File Size
Base name: readablesize
Description: Convert the size of a file to a readable format
Version: -
PHP version: 7.2
License: MIT/X Consortium License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Text processing Manipulating and validating text data View top rated classes
Group folder image Conversion Unit and datatype conversion View top rated classes


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file clover.xml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageSize (5 files)

  Files folder image Files  /  src  /  Size  
File Role Description
  Plain text file Size.php Class Class source
  Plain text file SizeException.php Class Class source
  Plain text file SizeFormat.php Class Class source
  Plain text file SizeName.php Class Class source
  Plain text file SizeSettings.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageSize (4 files)

  Files folder image Files  /  tests  /  Size  
File Role Description
  Plain text file SizeFormatTest.php Class Class source
  Plain text file SizeNameTest.php Class Class source
  Plain text file SizeSettingsTest.php Class Class source
  Plain text file SizeTest.php Class Class source

Download Download all files: readablesize.tar.gz readablesize.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.