{"id":41760735,"url":"https://github.com/chrisullyott/php-filesize","last_synced_at":"2026-01-25T02:09:58.887Z","repository":{"id":56952567,"uuid":"186184822","full_name":"chrisullyott/php-filesize","owner":"chrisullyott","description":"Easily calculate file sizes and convert between units.","archived":false,"fork":false,"pushed_at":"2021-10-17T22:53:49.000Z","size":58,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-27T14:48:47.044Z","etag":null,"topics":["php","size-calculation"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisullyott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-11T21:54:36.000Z","updated_at":"2025-06-21T16:31:11.000Z","dependencies_parsed_at":"2022-08-21T08:20:25.769Z","dependency_job_id":null,"html_url":"https://github.com/chrisullyott/php-filesize","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/chrisullyott/php-filesize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisullyott%2Fphp-filesize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisullyott%2Fphp-filesize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisullyott%2Fphp-filesize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisullyott%2Fphp-filesize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisullyott","download_url":"https://codeload.github.com/chrisullyott/php-filesize/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisullyott%2Fphp-filesize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28741738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T01:40:51.112Z","status":"online","status_checked_at":"2026-01-25T02:00:06.841Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","size-calculation"],"created_at":"2026-01-25T02:09:58.824Z","updated_at":"2026-01-25T02:09:58.881Z","avatar_url":"https://github.com/chrisullyott.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/chrisullyott/php-filesize/v/stable)](https://packagist.org/packages/chrisullyott/php-filesize)\n[![Total Downloads](https://poser.pugx.org/chrisullyott/php-filesize/downloads)](https://packagist.org/packages/chrisullyott/php-filesize)\n\n# php-filesize\n\nA flexible package for handling file sizes and converting between units.\n\n### Installation\n\nInclude in your project, or, install with [Composer](https://getcomposer.org/):\n\n```bash\n$ composer require chrisullyott/php-filesize\n```\n\n### Instantiate\n\nA `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.\n\n```php\nuse ChrisUllyott\\FileSize;\n\n$size = new FileSize('500 GB');\n```\n\n### Convert between units\n\nUse `as()` to export the size in another format.\n\n```php\necho $size-\u003eas('MB'); // 512000\n```\n\nA variety of file size strings are supported here as well.\n\n```php\necho $size-\u003eas('megabytes'); // 512000\n```\n\nThe second argument specifies decimal precision (default is `2`).\n\n```php\necho $size-\u003eas('TB', 3); // 0.488\n```\n\n### User-friendly formatting\n\nUse `asAuto()` to get a user-friendly string:\n\n```php\n$size = new FileSize('1234522678.12 KB');\n\necho $size-\u003easAuto(); // '1.15 TB'\n```\n\nOptionally, `asAuto()` also provides a decimal precision.\n\n```php\n$size = new FileSize('1234522678.12 KB');\n\necho $size-\u003easAuto(5); // '1.14974 TB'\n```\n\nOr, simply `echo` the object for the same functionality:\n\n```php\necho $size; // '1.15 TB'\n```\n\n### Modify the size\n\nTo make changes, use `add()`, `subtract()`, `multiplyBy()`, and `divideBy()`.\n\n```php\n$size = new FileSize('4 GB');\n\n$size-\u003eadd('2G')\n     -\u003esubtract('1 gigabytes')\n     -\u003emultiplyBy(4)\n     -\u003edivideBy(2);\n\necho $size; // '10.00 GB'\n```\n\nNegative values are supported. In the case below, 1.2 megabytes are subtracted:\n\n```php\n$size-\u003eadd('-1.2mb');\n```\n\nYou may also use `add()` and `subtract()` with an array of values:\n\n```php\n$size-\u003eadd(['50mb', '140mb', '1.2mb']);\n```\n\n### Number base\n\nThe 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:\n\n```php\n$size = new FileSize(10921134, 10);\n\necho $size; // '10.92 MB'\n```\n\n### Decimal separator\n\nThe 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.\n\n```php\n$size = new FileSize('1.234.522.678,12 KB', 2, ',');\n\necho $size; // '1,15 TB'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisullyott%2Fphp-filesize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisullyott%2Fphp-filesize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisullyott%2Fphp-filesize/lists"}