PHPackages                             jensostertag/uploadhelper - 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. jensostertag/uploadhelper

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

jensostertag/uploadhelper
=========================

A PHP library to process uploaded files

2.0.0(10mo ago)0956MITPHPPHP &gt;=8.1.0

Since Jun 8Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/Struktal/struktal-file-uploads)[ Packagist](https://packagist.org/packages/jensostertag/uploadhelper)[ RSS](/packages/jensostertag-uploadhelper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

File Upload Handler for PHP
===========================

[](#file-upload-handler-for-php)

This is a helper library for PHP that helps to process uploaded files.

PHP stores uploaded files in the `$_FILES` array. However, this array is not very trivial to use for multiple file uploads. This library provides an easy way to check whether a file upload should be allowed and to get the files in a more convenient way.

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

[](#installation)

To install this library, include it in your project using composer:

```
composer require struktal/struktal-file-uploads
```

Usage
-----

[](#usage)

**Upload a single file**The following example shows how to allow the upload of a single file.

Let's assume you have a form with a file input named `fileInputName`:

```

```

In your PHP script that is called when the form is submitted, use the `FileUpload` class to check whether the file upload should be allowed and to get the uploaded files:

```
$fileUpload = new FileUpload();

// File Upload Options
$fileUpload->setInputName("fileInputName") // Set the Name of the File Input
             ->setMultiple(false) // Only allow a single File
             ->setAllowedMimeTypes(["image/jpeg", "image/png"]) // Only allow JPEG and PNG Files
             ->setMaxSize(2) // Only allow Files up to 2 MiB
             ->handleUploadedFiles();

// Check if there were Errors during the Upload
if(!($fileUpload->successful())) {
    $errors = $fileUpload->getErrors();
    return;
}

// Get the uploaded File
$uploadedFile = $fileUpload->getFiles();
```

If the file upload was successful, the `$uploadedFile` will be an array with the following structure:

```
[
    [0] => [
        "name" => "file.jpeg",
        "type" => "image/jpeg",
        "tmp_name" => "/tmp/php/php1h4j1o",
        "error" => 0,
        "size" => 1024
    ]
]
```

**Upload multiple files**The following example shows how to allow the upload of multiple files.

Let's assume you have a form with a file input named `fileInputName`, with the `multiple` attribute set:

```

```

In your PHP script that is called when the form is submitted, use the `FileUpload` class to check whether the file upload should be allowed and to get the uploaded files:

```
$fileUpload = new FileUpload();

// File Upload Options
$fileUpload->setInputName("fileInputName") // Set the Name of the File Input
             ->setMultiple(true) // Allow multiple Files
             ->setAllowedMimeTypes(["image/jpeg", "image/png"]) // Only allow JPEG and PNG Files
             ->setMaxSize(2) // Only allow Files up to 2 MiB
             ->handleUploadedFiles();

// Check if there were Errors during the Upload
if(!($fileUpload->successful())) {
    $errors = $fileUpload->getErrors();
    return;
}

// Get the uploaded Files
$uploadedFiles = $fileUpload->getFiles();
```

If the file upload was successful, the `$uploadedFiles` will be an array with the following structure:

```
[
    [0] => [
        "name" => "file1.jpeg",
        "type" => "image/jpeg",
        "tmp_name" => "/tmp/php/php1h4j1o",
        "error" => 0,
        "size" => 1024
    ],
    [1] => [
        "name" => "file2.jpeg",
        "type" => "image/jpeg",
        "tmp_name" => "/tmp/php/php1h4j1o",
        "error" => 0,
        "size" => 1024
    ],
    // ...
]
```

**File upload options**The following options can be set for the file upload:

OptionDescriptionDefault`setInputName(string $inputName)`Sets the name of the file input.-`setMultiple(bool $multiple)`Sets whether multiple files should be allowed.`false``setAllowedMimeTypes(array $allowedMimeTypes)`Sets the allowed mime types.`[]` (All uploads will be rejected)`setMaxSize(int $maxSize)`Sets the maximum size of the file in MiB.`∞` (No maximum size)**Upload errors**You can check whether there were errors during the file upload with the `successful()` method. It returns `true` if there were no errors and `false` if there was at least one error.

Errors that occur during the file upload can be retrieved with the `getErrors()` method. It returns them as Enum values of the `UploadError` class. There are the following errors:

ErrorCodeDescription`UPLOAD_ERR_NOT_UPLOADED``0`The file was not uploaded via HTTP POST or the PHP upload error is not `UPLOAD_ERR_OK`.`UPLOAD_ERR_TYPE``1`The file type is not allowed.`UPLOAD_ERR_SIZE``2`The file size is too large.`UPLOAD_ERR_MULTIPLE``3`Multiple files were uploaded, but only a single file is allowed.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance55

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Total

2

Last Release

327d ago

Major Versions

1.0.0 → 2.0.02025-06-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49905418?v=4)[Jens Ostertag](/maintainers/JensOstertag)[@JensOstertag](https://github.com/JensOstertag)

---

Top Contributors

[![JensOstertag](https://avatars.githubusercontent.com/u/49905418?v=4)](https://github.com/JensOstertag "JensOstertag (5 commits)")

---

Tags

filesupload

### Embed Badge

![Health badge](/badges/jensostertag-uploadhelper/health.svg)

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

###  Alternatives

[uploadcare/uploadcare-php

Uploadcare PHP integration handles uploads and further operations with files by wrapping Upload and REST APIs.

1022.5M6](/packages/uploadcare-uploadcare-php)[unclecheese/dropzone

An HTML5 upload field for the CMS and frontend forms.

46130.7k6](/packages/unclecheese-dropzone)[vova07/yii2-fileapi-widget

The FileAPI widget for Yii2 framework.

4765.5k9](/packages/vova07-yii2-fileapi-widget)[delight-im/file-upload

Simple and convenient file uploads — secure by default

7210.7k2](/packages/delight-im-file-upload)[floor12/yii2-module-files

Yii2 module to upload and manage files to your models.

1612.4k6](/packages/floor12-yii2-module-files)[gaspertrix/laravel-backpack-dropzone-field

Add Dropzone support for Laravel Backpack

172.2k](/packages/gaspertrix-laravel-backpack-dropzone-field)

PHPackages © 2026

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