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.0.0(7mo ago)326.9k—0%2MITPHPPHP &gt;=8.0CI passing

Since May 10Pushed 7mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (22)Used By (2)

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

[](#webfiori-file)

A comprehensive PHP library for file operations, providing an object-oriented abstraction layer for reading, writing, uploading, and serving files with advanced features like 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/workflows/php84.yaml) [ ![](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/502240905c6c6cf3f7317b19762554a274d8d3bbd1e6897a2cf2b3533b6488c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656266696f72692f66696c653f636f6c6f723d6c696768742d677265656e) ](https://packagist.org/packages/webfiori/file)

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

[](#table-of-contents)

- [Installation](#installation)
- [Requirements](#requirements)
- [Supported PHP Versions](#supported-php-versions)
- [Key Features](#key-features)
- [Quick Start](#quick-start)
- [Core Classes](#core-classes)
- [Usage Examples](#usage-examples)
    - [Basic File Operations](#basic-file-operations)
        - [Reading Files](#reading-files)
        - [Writing Files](#writing-files)
        - [File Information](#file-information)
    - [File Upload](#file-upload)
        - [Basic Upload](#basic-upload)
        - [Upload as File Objects](#upload-as-file-objects)
        - [Upload Configuration](#upload-configuration)
    - [Base64 Encoding/Decoding](#base64-encodingdecoding)
    - [File Serving](#file-serving)
    - [Chunked Processing](#chunked-processing)
    - [MIME Type Detection](#mime-type-detection)
- [Working Example](#working-example)
- [Testing](#testing)
- [API Reference](#api-reference)
    - [File Class](#file-class)
    - [FileUploader Class](#fileuploader-class)
    - [UploadedFile Class](#uploadedfile-class)
    - [MIME Class](#mime-class)
- [Error Handling](#error-handling)
- [Security Considerations](#security-considerations)
- [Performance Tips](#performance-tips)
- [Contributing](#contributing)
- [License](#license)

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

[](#installation)

Install via Composer:

```
composer require webfiori/file
```

Requirements
------------

[](#requirements)

- **PHP**: 8.0 or higher
- **Dependencies**:
    - `webfiori/jsonx`: ^4.0 (JSON serialization)
    - `webfiori/http`: \* (HTTP response handling - dev dependency)

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

[](#supported-php-versions)

Build Status[![](https://github.com/WebFiori/file/actions/workflows/php80.yaml/badge.svg?branch=main)](https://github.com/WebFiori/file/actions/workflows/php80.yaml)[![](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)Key Features
------------

[](#key-features)

- **Object-Oriented File Operations**: Clean, intuitive API for file manipulation with comprehensive error handling
- **Advanced File Upload**: Multi-file upload with type validation, size limits, and detailed error reporting
- **Base64 Encoding/Decoding**: Built-in support for binary data encoding with strict validation options
- **MIME Type Detection**: Automatic MIME type detection for common file extensions
- **File Serving**: HTTP-compliant file serving with range request support for streaming
- **Chunked Processing**: Memory-efficient processing of large files with configurable chunk sizes
- **JSON Serialization**: Convert file objects to JSON for APIs and data interchange
- **Path Normalization**: Cross-platform path handling with automatic directory separator conversion
- **Security Features**: File type validation, directory traversal protection, and safe file operations
- **Comprehensive Testing**: Full test coverage with PHPUnit for reliability and stability

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

[](#quick-start)

```
