PHPackages                             webfiori/file - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. webfiori/file

ActiveLibrary[File &amp; Storage](/categories/file-storage)

webfiori/file
=============

Basic class library to read, write and view files using PHP.

2.1.1(1mo ago)329.2k↑1022.2%[28 issues](https://github.com/WebFiori/file/issues)4MITPHPPHP &gt;=8.1CI passing

Since May 10Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/WebFiori/file)[ Packagist](https://packagist.org/packages/webfiori/file)[ RSS](/packages/webfiori-file/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (10)Versions (31)Used By (4)

WebFiori File
=============

[](#webfiori-file)

A PHP library for file operations, providing an object-oriented abstraction layer for reading, writing, uploading, and serving files with streaming support, Base64 encoding/decoding, MIME type detection, and chunked file processing.

 [ ![](https://github.com/WebFiori/file/actions/workflows/php84.yaml/badge.svg?branch=main) ](https://github.com/WebFiori/file/actions) [ ![](https://camo.githubusercontent.com/c42c9f73476f9637e16d416318b2a2e4e239e01b520bfc6250a16c9ce5f82ee0/68747470733a2f2f636f6465636f762e696f2f67682f57656246696f72692f66696c652f6272616e63682f6d61696e2f67726170682f62616467652e737667) ](https://codecov.io/gh/WebFiori/file) [ ![](https://camo.githubusercontent.com/a63ccb7a37980c2f8d0628f8bb51e0413dc02e59d2d0508e5e2eb2d0d5d83742/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d57656246696f72695f66696c65266d65747269633d616c6572745f737461747573) ](https://sonarcloud.io/dashboard?id=WebFiori_file) [ ![](https://camo.githubusercontent.com/80c971bbd9861e054c3cbaadbdf8dfcbb3239b609cd32961420ac0974d67c596/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f57656246696f72692f66696c652e7376673f6c6162656c3d6c6174657374) ](https://github.com/WebFiori/file/releases) [ ![](https://camo.githubusercontent.com/502240905c6c6cf3f7317b19762554a274d8d3bbd1e6897a2cf2b3533b6488c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656266696f72692f66696c653f636f6c6f723d6c696768742d677265656e) ](https://packagist.org/packages/webfiori/file) [![PHP 8.1+](https://camo.githubusercontent.com/6518db1335bf20fdff07253dc6d6d0cec955b5fb6a8ef1382ac6d73687ecc07f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c7565)](https://camo.githubusercontent.com/6518db1335bf20fdff07253dc6d6d0cec955b5fb6a8ef1382ac6d73687ecc07f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c7565)

Table of Contents
-----------------

[](#table-of-contents)

- [Supported PHP Versions](#supported-php-versions)
- [Key Features](#key-features)
- [Why This Library?](#why-this-library)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Core Classes](#core-classes)
- [Using FileInterface](#using-fileinterface)
- [Examples](#examples)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)
- [Support](#support)
- [Changelog](#changelog)

Supported PHP Versions
----------------------

[](#supported-php-versions)

Build Status[![](https://github.com/WebFiori/file/actions/workflows/php81.yaml/badge.svg?branch=main)](https://github.com/WebFiori/file/actions/workflows/php81.yaml)[![](https://github.com/WebFiori/file/actions/workflows/php82.yaml/badge.svg?branch=main)](https://github.com/WebFiori/file/actions/workflows/php82.yaml)[![](https://github.com/WebFiori/file/actions/workflows/php83.yaml/badge.svg?branch=main)](https://github.com/WebFiori/file/actions/workflows/php83.yaml)[![](https://github.com/WebFiori/file/actions/workflows/php84.yaml/badge.svg?branch=main)](https://github.com/WebFiori/file/actions/workflows/php84.yaml)[![](https://github.com/WebFiori/file/actions/workflows/php85.yaml/badge.svg?branch=main)](https://github.com/WebFiori/file/actions/workflows/php85.yaml)Key Features
------------

[](#key-features)

- Object-oriented file read, write, create, remove, copy, and move
- Streaming I/O with constant memory usage via `FileStream`
- File upload handling with extension validation, size limits, and callback hooks
- Stream processing during uploads with hash verification support
- Atomic writes (temp + rename) for crash-safe operations
- Base64 encoding/decoding
- Byte-range reads for partial file access
- MIME type detection for ~600 file extensions
- `ResponseEmitter` interface for framework-agnostic HTTP file serving
- `FileInterface` for dependency injection and mocking

Why This Library?
-----------------

[](#why-this-library)

- **All-in-one** — File I/O, uploads, streaming, and HTTP serving in a single package.
- **Upload-first design** — `FileUploader`, `StreamingUploader`, and `ResumableUploader` handle multipart forms, raw body streams, and chunked uploads with pause/resume — each with extension filtering, size limits, and callback hooks.
- **Constant-memory streaming** — Generators power reads, writes, uploads, and serving. Process gigabyte files without touching memory limits.
- **Framework-agnostic HTTP serving** — The `ResponseEmitter` interface decouples file serving from any specific HTTP layer. Plug in PSR-7, any framework, or raw PHP.
- **Testable by design** — `FileInterface` enables dependency injection and mocking. No filesystem required in your unit tests.
- **Lightweight** — Single dependency, no framework coupling.

Installation
------------

[](#installation)

```
composer require webfiori/file
```

**Requirements:**

- PHP 8.1 or higher
- `webfiori/jsonx` ^4.0

Quick Start
-----------

[](#quick-start)

```
