PHPackages                             chrisullyott/php-filesize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chrisullyott/php-filesize

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chrisullyott/php-filesize
=========================

Easily calculate file sizes and convert between units.

v4.2.1(4y ago)8185.8k↑54.9%[1 issues](https://github.com/chrisullyott/php-filesize/issues)6MITPHPPHP &gt;=7.1CI failing

Since May 11Pushed 4y agoCompare

[ Source](https://github.com/chrisullyott/php-filesize)[ Packagist](https://packagist.org/packages/chrisullyott/php-filesize)[ Docs](https://github.com/chrisullyott/php-filesize)[ RSS](/packages/chrisullyott-php-filesize/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (1)Versions (24)Used By (6)

[![Latest Stable Version](https://camo.githubusercontent.com/e2cfb3777cdb11ad5db8e4aa500241896194744401c8a202760042e09ae41833/68747470733a2f2f706f7365722e707567782e6f72672f6368726973756c6c796f74742f7068702d66696c6573697a652f762f737461626c65)](https://packagist.org/packages/chrisullyott/php-filesize)[![Total Downloads](https://camo.githubusercontent.com/ef9fd5314e13955124ed0c8fb30d2f167634e875bc7d61bb66f2c3660e5bfd3e/68747470733a2f2f706f7365722e707567782e6f72672f6368726973756c6c796f74742f7068702d66696c6573697a652f646f776e6c6f616473)](https://packagist.org/packages/chrisullyott/php-filesize)

php-filesize
============

[](#php-filesize)

A flexible package for handling file sizes and converting between units.

### Installation

[](#installation)

Include in your project, or, install with [Composer](https://getcomposer.org/):

```
$ composer require chrisullyott/php-filesize
```

### Instantiate

[](#instantiate)

A `FileSize` object, both on creation and within its methods, understands just about any expression of data size. You may instantiate it with a size, or leave it initially empty.

```
use ChrisUllyott\FileSize;

$size = new FileSize('500 GB');
```

### Convert between units

[](#convert-between-units)

Use `as()` to export the size in another format.

```
echo $size->as('MB'); // 512000
```

A variety of file size strings are supported here as well.

```
echo $size->as('megabytes'); // 512000
```

The second argument specifies decimal precision (default is `2`).

```
echo $size->as('TB', 3); // 0.488
```

### User-friendly formatting

[](#user-friendly-formatting)

Use `asAuto()` to get a user-friendly string:

```
$size = new FileSize('1234522678.12 KB');

echo $size->asAuto(); // '1.15 TB'
```

Optionally, `asAuto()` also provides a decimal precision.

```
$size = new FileSize('1234522678.12 KB');

echo $size->asAuto(5); // '1.14974 TB'
```

Or, simply `echo` the object for the same functionality:

```
echo $size; // '1.15 TB'
```

### Modify the size

[](#modify-the-size)

To make changes, use `add()`, `subtract()`, `multiplyBy()`, and `divideBy()`.

```
$size = new FileSize('4 GB');

$size->add('2G')
     ->subtract('1 gigabytes')
     ->multiplyBy(4)
     ->divideBy(2);

echo $size; // '10.00 GB'
```

Negative values are supported. In the case below, 1.2 megabytes are subtracted:

```
$size->add('-1.2mb');
```

You may also use `add()` and `subtract()` with an array of values:

```
$size->add(['50mb', '140mb', '1.2mb']);
```

### Number base

[](#number-base)

The second argument of the constructor is the number base, which accepts either `2` (binary) or `10` (decimal). We use binary by default. To handle sizes in decimal:

```
$size = new FileSize(10921134, 10);

echo $size; // '10.92 MB'
```

### Decimal separator

[](#decimal-separator)

The third argument of the constructor is the decimal separator, which is a period `.` by default. Here, you can use a comma instead. The chosen decimal separator will be used both to parse numbers properly, and also to format them on output.

```
$size = new FileSize('1.234.522.678,12 KB', 2, ',');

echo $size; // '1,15 TB'
```

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~169 days

Total

23

Last Release

1696d ago

Major Versions

v1.1.0 → v2.0.02019-05-28

v2.1.0 → v3.0.02019-05-29

v3.2.0 → v4.0.02019-11-07

PHP version history (2 changes)v1.0.0PHP &gt;=5.6.0

v4.1.2PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1007459?v=4)[Chris](/maintainers/chrisullyott)[@chrisullyott](https://github.com/chrisullyott)

---

Top Contributors

[![chrisullyott](https://avatars.githubusercontent.com/u/1007459?v=4)](https://github.com/chrisullyott "chrisullyott (85 commits)")

---

Tags

phpsize-calculationphpsize-calculation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chrisullyott-php-filesize/health.svg)

```
[![Health](https://phpackages.com/badges/chrisullyott-php-filesize/health.svg)](https://phpackages.com/packages/chrisullyott-php-filesize)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21422.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
