PHPackages                             didslm/file-upload-wrapper - 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. didslm/file-upload-wrapper

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

didslm/file-upload-wrapper
==========================

This wrapper makes file uploading easier to use

1.1.1(2y ago)22771[1 issues](https://github.com/didslm/file-upload-wrapper/issues)[1 PRs](https://github.com/didslm/file-upload-wrapper/pulls)MITPHPPHP &gt;=8.0

Since Mar 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/didslm/file-upload-wrapper)[ Packagist](https://packagist.org/packages/didslm/file-upload-wrapper)[ RSS](/packages/didslm-file-upload-wrapper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

File Upload Wrapper
===================

[](#file-upload-wrapper)

The File Upload Wrapper is a PHP library that simplifies file uploads by providing a set of easy-to-use classes that handle common validation and processing tasks. With this library, you can:

- Validate uploaded files with ease
- Process uploaded files with targeted validations for specific fields
- Simplify the file upload process with a set of easy-to-use classes

Getting Started
===============

[](#getting-started)

To use the library, follow these steps:

1. Install the library using Composer:

```
composer require didslm/file-upload-wrapper
```

2. Import the classes you need:

```
use Didslm\FileUpload\Uploader;
use Didslm\FileUpload\UploaderInterface;
use Didslm\FileUpload\File;
use Didslm\FileUpload\Validation\FileSize;
use Didslm\FileUpload\Validation\FileType;
use Didslm\FileUpload\Validation\Dimension;
use Didslm\FileUpload\FieldValidation;
use Didslm\FileUpload\Attributes\Image;
use Didslm\FileUpload\Attributes\Document;
use Didslm\FileUpload\Exceptions\FileUploadException;
```

3. Use the `upload()` method to handle file uploads for your entity:

```
class Product {
    #[Image(requestField: "request_field", dir: "/public")]
    private string $image;

    #[Image(requestField: "profile_field", dir: "/public")]
    private string $profile;

    // ...
}

$product = new Product();

Uploader::upload($product, [
    new FileType([File::JPEG]),
    new FileSize(2, File::MB)
]);
```

4. The same exmaple you can do via Dependency Injection:

```
class ProductController {
    public function __construct(private UploaderInterface $uploader){}

    public function upload(Request $request)
    {
        $product = new Product();

        $this->uploader->upload($product, [
            new FileType([File::IMAGES]),
            new FileSize(2, File::MB)
        ]);
    }
}
```

At the end of this document you can see how to configure in Laravel or Symfony.

---

Examples
========

[](#examples)

### Handling File Uploads for an Entity

[](#handling-file-uploads-for-an-entity)

The following code shows an example of how to use the library to handle file uploads for an entity:

```
class Product {
    //...
    #[Image(requestField: "request_field", dir: "/public")]
    private string $image;

    #[Image(requestField: "profile_field", dir: "/public")]
    private string $profile;

    public function getImageFilename(): string
    {
        return $this->image;
    }

    public function getProfileFilename(): string
    {
        return $this->profile;
    }
}
```

In this example, the `Product` class has two properties `image` and `profile` that are decorated with the `Image` attribute.

### Types

[](#types)

In the following example you will see a list of available Attribute types:

```
#[new Image(requestName: 'file_upload_field', dir: '/upload/dir')]
#[new Document(requestName: 'cv_file', dir: '/upload/dir')]
#[new Video(requestName: 'video_file', dir: '/upload/dir')]
```

The `Image` attribute provides metadata to the library to process the files correctly during the upload.

The `Document` attribute provides metadata to the library to process the files correctly during the upload.

The `Video` attribute provides metadata to the library to process the files correctly during the upload.

The `upload()` method is then called on the `Uploader` class with the `Product` object and an array of validation rules as its parameters.

```
$product = new Product();

Uploader::upload($product, [
    new FileType([File::JPEG]),
    new FileSize(2, File::MB)
]);

echo $product->getImageFilename();
```

Handling Exceptions
===================

[](#handling-exceptions)

The library provides a `FileUploadException` class that all exceptions thrown by the library extend. This means that you can catch all exceptions using `FileUploadException` in a try-catch block, as shown below:

```
try {
    Uploader::upload($product, [
        new FileType([File::PNG]),
        new FileSize(2, File::MB)
    ]);
} catch (FileUploadException $e) {
    // handle exception
}
```

Validation
==========

[](#validation)

The library provides several validation classes that you can use to validate uploaded files. These classes can be passed as parameters to the `upload()` method to specify the validation rules for the files being uploaded.

### Type

[](#type)

The `FileType` class is used to check the file type. You can specify the types of files allowed by passing an array of file types to the constructor. For example:

```
new FileType([File::PNG, File::JPEG, File::GIF])
```

### Size

[](#size)

The `FileSize` class is used to validate the file size. You can specify the maximum file size allowed by passing the size in bytes to the constructor. Alternatively, you can use the Size class to specify the size in a more readable format. For example:

```
new FileSize(2, File::MB)
new FileSize(200, File::KB)
```

### Dimension

[](#dimension)

The `Dimension` class is used to validate the dimensions of images. You can specify the maximum width and height of the image by passing them as parameters to the constructor. For example:

```
new Dimension(200, 200)
```

### Targeted Validations

[](#targeted-validations)

You can also target specific fields in your entity with a set of validations. To do this, you can use the `FieldValidations` class, which takes the request field name as it's first parameter and an array of validation rules as its second parameter. Here's an example:

```
$profileValidations = new FieldValidations("profile_field", [
    new Dimension(200, 200),
    new FileSize(2, File::MB)
]);

Uploader::upload($product, [
    new FileType([File::PNG, File::JPEG, File::GIF]),
    $profileValidations,
]);
```

In the example above, we are specifying a set of validation checks that apply to the profile field in the Product entity. These checks will only be applied to the profile image uploaded by the user.

Frameworks Implementation
=========================

[](#frameworks-implementation)

The library is framework agnostic, which means that you can use it with any framework.

The following sections show how to configure the library in some of the most popular frameworks.

Symfony
-------

[](#symfony)

In your Symfony app you can easily configure the library in your `services.yaml` file:

```
services:
    Didslm\FileUpload\:
        resource: '../vendor/didslm/file-upload-wrapper/src/*'
```

Laravel
-------

[](#laravel)

In your Laravel app you can easily configure the library in your `AppServiceProvider.php` file:

```
public function register()
{
    $this->app->bind(UploaderInterface::class, function (){
         return UploaderFactory::create();
    });
}
```

---

Handling file uploads can be a complicated and error-prone task, but with this library, you can simplify the process and focus on building the features that matter. If you have any questions or feedback, feel free to reach out to the author on [Twitter](https://twitter.com/slmdiar) or [LinkedIn](https://linkedin.com/in/diarselimi).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Total

3

Last Release

990d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a66a37c065b686ab7f65c7b1ec7038aa0a696272d7158d7245c25b11949986a?d=identicon)[didslm](/maintainers/didslm)

---

Top Contributors

[![didslm](https://avatars.githubusercontent.com/u/8136247?v=4)](https://github.com/didslm "didslm (51 commits)")

---

Tags

file-uploadphp8

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/didslm-file-upload-wrapper/health.svg)

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k511.3M2.2k](/packages/aws-aws-sdk-php)[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[stechstudio/laravel-zipstream

A fast and simple streaming zip file downloader for Laravel.

4633.7M3](/packages/stechstudio-laravel-zipstream)

PHPackages © 2026

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