PHPackages                             enjoys/upload - 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. enjoys/upload

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

enjoys/upload
=============

4.3.0(2mo ago)02.4k↓50%[6 issues](https://github.com/Enjoyzz/upload/issues)2MITPHPPHP ~8.2.0 | ~8.3.0 | ~8.4.0 | ~8.5.0CI passing

Since Jul 14Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Enjoyzz/upload)[ Packagist](https://packagist.org/packages/enjoys/upload)[ Docs](https://github.com/Enjoyzz/upload)[ RSS](/packages/enjoys-upload/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (10)Versions (21)Used By (2)

Upload
======

[](#upload)

[![Mutation testing badge](https://camo.githubusercontent.com/96bdbeb8751e192907815271aff07579651f493233ad24c9bb46c21ebf55f9c9/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246456e6a6f797a7a25324675706c6f61642532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/Enjoyzz/upload/master)[![tests](https://github.com/Enjoyzz/upload/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/Enjoyzz/upload/actions/workflows/tests.yml)[![static](https://github.com/Enjoyzz/upload/actions/workflows/static.yml/badge.svg?branch=master)](https://github.com/Enjoyzz/upload/actions/workflows/static.yml)[![Build Status](https://camo.githubusercontent.com/0a62127fee8d909a673631da4f57ca4993a2d8dbefc4b224c716df006041c4f9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f456e6a6f797a7a2f75706c6f61642f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Enjoyzz/upload/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8aa2428cd3629c409b972007e0befa86407330ff099e5024826c55ec4af15fb0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f456e6a6f797a7a2f75706c6f61642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Enjoyzz/upload/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/81682c5680758c685ecde0f3783f9593bb3afa5eda9c5760df7605b23beced1e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f456e6a6f797a7a2f75706c6f61642f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Enjoyzz/upload/?branch=master)

File uploads library with validation uses [PSR-7 UploadedFileInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#16-uploaded-files)and [League\\Flysystem](https://github.com/thephpleague/flysystem) as a file storage library

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

[](#installation)

> Requires PHP 8.2 or later.

Install via Composer:

```
composer require enjoys/upload:^4.0
```

### Basic Usage

[](#basic-usage)

```
use Psr\Http\Message\ServerRequestInterface;

/** @var Psr\Http\Message\UploadedFileInterface $uploadedFile */
/** @var League\Flysystem\Filesystem $filesystem */

$file = new Enjoys\Upload\UploadProcessing($uploadedFile, $filesystem);

try {
    $file->upload();
} catch (\Exception $e) {
    // Handle exception
}
```

### Validation Rules

[](#validation-rules)

The library includes *3 built-in validation rules*. You can also create custom rules by implementing `Enjoys\Upload\RuleInterface`.

#### Available rules:

[](#available-rules)

- Extension (Enjoys\\Upload\\Rule\\Extension) — Validates file extensions
- Size (Enjoys\\Upload\\Rule\\Size) — Validates file size
- MediaType (Enjoys\\Upload\\Rule\\MediaType) — Validates MIME types

#### Adding Validation Rules

[](#adding-validation-rules)

```
/** @var Enjoys\Upload\UploadProcessing $file */
/** @var Enjoys\Upload\RuleInterface $rule */

$file->addRule($rule); // Add before calling upload()
$file->upload();
```

##### Extension Rule

[](#extension-rule)

Case-insensitive extension validation:

```
$rule = new Enjoys\Upload\Rule\Extension();
$rule->allow('png'); // Single extension
$rule->allow('png, jpg'); // Comma-separated
$rule->allow(['png', 'jpg']); // Array of extensions
```

##### Size Rule

[](#size-rule)

```
$rule = new Enjoys\Upload\Rule\Size();
$rule->setMaxSize(10 * 1024 * 1024) // 10MB
     ->setMinSize(1 * 1024 * 1024); // 1MB (values in bytes)
```

##### MediaType Rule

[](#mediatype-rule)

```
$rule = new Enjoys\Upload\Rule\MediaType();
$rule->allow('image/*') // All image types
     ->allow('application/pdf') // PDF files
     ->allow('*/vnd.openxmlformats-officedocument.*'); // Office documents
$rule->allow('*'); // All types
```

### Event System

[](#event-system)

The library provides PSR-14 compatible events:

#### Available Events:

[](#available-events)

- **`BeforeValidationEvent`** - Dispatched before validation starts
- **`BeforeUploadEvent`** - Dispatched after validation, before file upload
- **`AfterUploadEvent`** - Dispatched after successful file upload
- **`UploadErrorEvent`** - Dispatched when any error occurs

#### Usage Example:

[](#usage-example)

```
use Enjoys\Upload\Event\AfterUploadEvent;
use Psr\EventDispatcher\EventDispatcherInterface;

/** @var EventDispatcherInterface $dispatcher */

// Initialize with event dispatcher
$upload = new UploadProcessing($uploadedFile, $filesystem, $dispatcher);

// Add event listener
$dispatcher->addListener(
    AfterUploadEvent::class,
    function (AfterUploadEvent $event) {
        logger()->info("File uploaded to: " . $event->uploadProcessing->getTargetPath());
    }
);

$upload->upload();
```

#### Event Propagation:

[](#event-propagation)

All events implement `StoppableEventInterface`. To stop further processing:

```
$dispatcher->addListener(
    BeforeUploadEvent::class,
    function (BeforeUploadEvent $event) {
        if ($shouldStop) {
            $event->stopPropagation(); // Stops other listeners
        }
    }
);
```

### API Reference

[](#api-reference)

#### Enjoys\\Upload\\UploadProcessing::class

[](#enjoysuploaduploadprocessingclass)

**setFilename(filename: string)**

Sets a new filename for the uploaded file (call before upload).

**addRule(rule: Enjoys\\Upload\\RuleInterface)**

Adds a single validation rule (call before upload).

**addRules(rules: Enjoys\\Upload\\RuleInterface\[\])**

Adds multiple validation rules (call before upload).

**upload(targetPath: string)**

Processes the file upload. Optionally specify a subdirectory.

**getTargetPath(): ?string**

Returns the file storage path after upload, or null if not uploaded.

**getFilesystem()**

Returns the `League\Flysystem\Filesystem::class` instance.

**getUploadedFile(): UploadedFileInterface**

Returns the PSR-7 UploadedFileInterface instance.

**getFileInfo()**

Returns the FileInfo object with file metadata.

#### Enjoys\\Upload\\FileInfo::class

[](#enjoysuploadfileinfoclass)

**getFilename(): string**

Returns the full filename (e.g., new\_file\_name.jpg).

**getOriginalFilename(): string**

Returns the original uploaded filename.

**getFilenameWithoutExtension(): string**

Returns the filename without extension.

**getExtension(): string**

Returns the file extension (without dot).

**getExtensionWithDot(): string**

Returns the file extension with leading dot.

**getSize(): int**

Returns the file size in bytes.

**getMediaType(): string**

Returns the client-reported MIME type.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance84

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity74

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 ~77 days

Recently: every ~61 days

Total

18

Last Release

82d ago

Major Versions

1.0.2 → 2.0.02022-07-17

2.0.0 → 3.0.02022-07-22

3.0.8 → 4.0.02025-06-26

PHP version history (5 changes)1.0.2PHP &gt;= 8.0

3.0.6PHP ^8.0

3.0.8PHP ~8.0.0 | ~8.1.0 | ~8.2.0 | ~8.3.0 | ~8.4.0

4.0.0PHP ~8.2.0 | ~8.3.0 | ~8.4.0

4.3.0PHP ~8.2.0 | ~8.3.0 | ~8.4.0 | ~8.5.0

### Community

Maintainers

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

---

Top Contributors

[![Enjoyzz](https://avatars.githubusercontent.com/u/1448659?v=4)](https://github.com/Enjoyzz "Enjoyzz (87 commits)")

---

Tags

filefile-uploadfilesfilesystemphpuploads3storageuploaduploaderuploadenjoys

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/enjoys-upload/health.svg)

```
[![Health](https://phpackages.com/badges/enjoys-upload/health.svg)](https://phpackages.com/packages/enjoys-upload)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[sonata-project/media-bundle

Symfony SonataMediaBundle

4625.5M71](/packages/sonata-project-media-bundle)[yangyifan/upload

上传 SDK for Laravel

12422.6k3](/packages/yangyifan-upload)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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