A PHP library for file operations, providing an object-oriented abstraction layer for reading, writing, uploading, and serving files with Base64 encoding/decoding, MIME type detection, and chunked file processing.
composer require webfiori/file- PHP 8.1 or higher
webfiori/jsonx^4.0
| Build Status |
|---|
<?php
require_once 'vendor/autoload.php';
use WebFiori\File\File;
$file = new File('/path/to/document.txt');
$file->read();
echo $file->getRawData();File— Read, write, create, remove, and serve files. Supports byte-range reads, Base64 encoding/decoding, chunked processing, and JSON serialization.FileUploader— Handle file uploads with extension validation, size limits, and detailed error reporting.UploadedFile— ExtendsFilewith upload-specific properties (upload status, replacement status, error message).MIME— Static lookup of ~600 file extension to MIME type mappings.
The examples/ directory contains runnable PHP scripts covering every feature of the library:
| Example | Description |
|---|---|
| Reading and Writing Files | Create, write, read, append, and remove files |
| File Information | File metadata: name, extension, MIME, size, timestamps, constructor variants |
| Partial Read | Read specific byte ranges from a file |
| Appending Data | Build up in-memory content with append() |
| Base64 Encoding | Encode/decode Base64, writeEncoded(), readDecoded() |
| Chunked Processing | Split file data into fixed-size chunks |
| Bytes and Hex | Convert data to byte arrays and hex strings |
| MIME Detection | Look up MIME types by extension |
| Error Handling | FileException scenarios and how to handle them |
| JSON Serialization | Convert File objects to JSON |
| Path Utilities | Path normalization, directory creation, file existence checks |
| File Upload | Configure and process uploads with FileUploader |
| Serving Files | Serve files over HTTP with proper headers |
Each example has its own README with detailed explanations. Run any example with:
php examples/read-and-write/read-and-write.php# Run all tests
composer test
# Run tests with PHPUnit 10
composer test10- Fork the repository and create a feature branch
- Write tests for new functionality
- Follow PSR-12 coding standards
- Submit a pull request
MIT — see LICENSE for details.