PHP Classes

PHP File Size Human Readable: Format files in terms of B, KB, MB, GB, TB

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 143 All time: 9,173 This week: 488Up
Version License PHP version Categories
prettysize 1.0.0MIT/X Consortium ...7.1Files and Folders, Text processing, P...
Description 

Author

This class can format files in terms of B, KB, MB, GB, TB.

It can take a number of bytes and returns a formatted string it so it is easier to read by humans.

The class can format the number with options that allow to configure several details like the number of decimal places that may be returned, show a space between the formatted number and the size suffix, or to return the suffix with one or two letters.

Picture of Ankit Jain
Name: Ankit Jain <contact>
Classes: 4 packages by
Country: India India
Age: 28
All time rank: 3299217 in India India
Week rank: 256 Up18 in India India Up
Innovation award
Innovation award
Nominee: 2x

Documentation

About prettysize

prettysize was created by, and is maintained by Ankit Jain, and is a helper utility to provide pretty printed file sizes.

Build Status Coverage Status Latest Stable Version

Installation & Usage

> Requires PHP 7.1+

Require prettysize using Composer:

composer require ankitjain28may/prettysize

Arguments

Pretty::pretty($size, $nospace, $one, $places);

/*
  $size : Size in bytes to be converted (Required)
  $nospace : Remove space from the output (Default - false)
  $one : Single character for the size (Default - false)
  $places : Number of decimal places to return (Default - 1)
 */

use Ankitjain28may\Prettysize\Pretty;

$size = Pretty::pretty(1024);
// $size = "1.0 kB"

$size = Pretty::pretty(1024, true, true, 2);
// $size = "1.00k"

$size = Pretty::pretty(1024, ['nospace' => true, 'one' => true, 'places' => 5]);
// $size = "1.00000k"

Contributing

Thank you for considering to contribute to prettysize. You can also follow the twitter account for latest announcements or just come say hi!: @ankitjain28may

License

prettysize is an open-sourced library licensed under the MIT license.


  Files folder image Files (10)  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file coverage.xml 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
Accessible without login Plain text file ruleset.xml Data Auxiliary data

  Files folder image Files (10)  /  src  
File Role Description
  Plain text file Pretty.php Class Class source

  Files folder image Files (10)  /  tests  
File Role Description
  Plain text file PrettyTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:143
This week:0
All time:9,173
This week:488Up