PHPackages                             mahmut/fileupload - 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. mahmut/fileupload

ActiveLibrary

mahmut/fileupload
=================

File uploading library capable of handling large/chunked/multiple file uploads

v1.5.2(4y ago)028MITPHPPHP ~7.2|~8.0

Since Aug 25Pushed 4y agoCompare

[ Source](https://github.com/mahmut/fileupload)[ Packagist](https://packagist.org/packages/mahmut/fileupload)[ RSS](/packages/mahmut-fileupload/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (23)Used By (0)

FileUpload
==========

[](#fileupload)

[![Build Status](https://camo.githubusercontent.com/dd140afd0b0fe6e3daf5c9edf44d1b6930ba148b58f4d680e99f948447a7ae29/68747470733a2f2f7472617669732d63692e6f72672f47617267726f6e2f66696c6575706c6f61642e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Gargron/fileupload)

PHP FileUpload library that supports chunked uploads. Adopted from the procedural script included with [jQuery-File-Upload](https://github.com/blueimp/jQuery-File-Upload), designed to work with that JavaScript plugin, with normal forms, and to be embeddable into any application/architecture.

### Installing

[](#installing)

This package is available via Composer:

```
{
  "require": {
    "mahmut/fileupload": "~1.0.0"
  }
}
```

### Requirements

[](#requirements)

- Ensure that the PHP extension "php\_fileinfo" is enabled;
- Your php.ini must have the next directive:

`file_uploads = On`

### Status

[](#status)

The unit test suite covers simple uploads and the library "works on my machine", as it were. You are welcome to contribute.

You can grep the source code for `TODO` to find things you could help finishing.

### Usage

[](#usage)

```
// Simple validation (max file size 2MB and only two allowed mime types)
$validator = new FileUpload\Validator\Simple('2M', ['image/png', 'image/jpg']);

// Simple path resolver, where uploads will be put
$pathresolver = new FileUpload\PathResolver\Simple('/my/uploads/dir');

// The machine's filesystem
$filesystem = new FileUpload\FileSystem\Simple();

// FileUploader itself
$fileupload = new FileUpload\FileUpload($_FILES['files'], $_SERVER);

// Adding it all together. Note that you can use multiple validators or none at all
$fileupload->setPathResolver($pathresolver);
$fileupload->setFileSystem($filesystem);
$fileupload->addValidator($validator);

// Doing the deed
list($files, $headers) = $fileupload->processAll();

// Outputting it, for example like this
foreach($headers as $header => $value) {
    header($header . ': ' . $value);
}

echo json_encode(['files' => $files]);

foreach($files as $file){
    //Remeber to check if the upload was completed
    if ($file->completed) {
        echo $file->getRealPath();

        // Call any method on an SplFileInfo instance
        var_dump($file->isFile());
    }
}
```

### Alternative usage via factory

[](#alternative-usage-via-factory)

```
$factory = new FileUploadFactory(
    new PathResolver\Simple('/my/uploads/dir'),
    new FileSystem\Simple(),
    [
        new FileUpload\Validator\MimeTypeValidator(['image/png', 'image/jpg']),
        new FileUpload\Validator\SizeValidator('3M', '1M')
        // etc
    ]
);

$instance = $factory->create($_FILES['files'], $_SERVER);
```

### Validators

[](#validators)

There are currently 4 validators shipped with `FileUpload`:

- `Simple`

```
// Simple validation (max file size 2MB and only two allowed mime types)
$validator = new FileUpload\Validator\Simple('2M', ['image/png', 'image/jpg']);
```

- `MimeTypeValidator`

```
$mimeTypeValidator = new FileUpload\Validator\MimeTypeValidator(['image/png', 'image/jpg']);
```

- `SizeValidator`

```
// The 1st parameter is the maximum size while the 2nd is the minimum size
$sizeValidator = new FileUpload\Validator\SizeValidator('3M', '1M');
```

- `DimensionValidator`

```
$config = [
     'width' => 400,
     'height' => 500
];
// Can also contain 'min_width', 'max_width', 'min_height' and 'max_height'

$dimensionValidator = new FileUpload\Validator\DimensionValidator($config);
```

> Remember to register new validator(s) by `$fileuploadInstance->addValidator($validator);`

If you want you can use the common human readable format for filesizes like '1M', '1G', just pass the string as the first argument.

```
$validator = new FileUpload\Validator\Simple('10M', ['image/png', 'image/jpg']);

```

Here is a listing of the possible values (B =&gt; B; KB =&gt; K; MB =&gt; M; GB =&gt; G). These values are binary convention so basing on 1024.

### FileNameGenerator

[](#filenamegenerator)

With the `FileNameGenerator` you have the possibility to change the filename the uploaded files will be saved as.

```
$fileupload = new FileUpload\FileUpload($_FILES['files'], $_SERVER);
$filenamegenerator = new FileUpload\FileNameGenerator\Simple();
$fileupload->setFileNameGenerator($filenamegenerator);
```

- `Custom`

```
$customGenerator = new FileUpload\FileNameGenerator\Custom($provider);
//$provider can be a string (in which case it is returned as is)
//It can also be a callable or a closure which receives arguments in the other of $source_name, $type, $tmp_name, $index, $content_range, FileUpload $upload
```

- `MD5`

```
$md5Generator = new FileUpload\FileNameGenerator\MD5($allowOverride);
//$allowOverride should be a boolean. A true value would overwrite the file if it exists while a false value would not allow the file to be uploaded since it already exists.
```

- `Random`

```
$randomGenerator = new FileUpload\FileNameGenerator\Random($length);
//Where $length is the maximum length of the generator random name
```

- `Simple`

```
$simpleGenerator = new FileUpload\FileNameGenerator\Simple();
//Saves a file by it's original name
```

- `Slug`

```
$slugGenerator = new FileUpload\FileNameGenerator\Slug();
//This generator slugifies the name of the uploaded file(s)
```

> Remember to register new validator(s) by `$fileuploadInstance->setFileNameGenerator($generator);`

> Every call to `setFileNameGenerator` overrides the currently set `$generator`

### Callbacks

[](#callbacks)

Currently implemented events:

- `completed`

```
$fileupload->addCallback('completed', function(FileUpload\File $file) {
    // Whoosh!
});
```

- `beforeValidation`

```
$fileUploader->addCallback('beforeValidation', function (FileUpload\File $file) {
    // About to validate the upload;
});
```

- `afterValidation`

```
$fileUploader->addCallback('afterValidation', function (FileUpload\File $file) {
    // Yay, we got only valid uploads
});
```

### Extending

[](#extending)

The reason why the path resolver, the validators and the file system are abstracted, is so you can write your own, fitting your own needs (and also, for unit testing). The library is shipped with a bunch of "simple" implementations which fit the basic needs. You could write a file system implementation that works with Amazon S3, for example.

### License

[](#license)

Licensed under the MIT license, see `LICENSE` file.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~407 days

Total

19

Last Release

1693d ago

Major Versions

v0.1 → v1.0.02013-09-19

PHP version history (2 changes)v1.5.0PHP ~7.0

v1.5.2PHP ~7.2|~8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/67c281c6bd022892b09084c73a854145d7a4ccbcb1a06455b268c36a84f45cf5?d=identicon)[mahmutozdemir](/maintainers/mahmutozdemir)

---

Top Contributors

[![Gargron](https://avatars.githubusercontent.com/u/184731?v=4)](https://github.com/Gargron "Gargron (39 commits)")[![adelowo](https://avatars.githubusercontent.com/u/12677701?v=4)](https://github.com/adelowo "adelowo (20 commits)")[![radmax](https://avatars.githubusercontent.com/u/1110762?v=4)](https://github.com/radmax "radmax (17 commits)")[![thenovacreator](https://avatars.githubusercontent.com/u/2353240?v=4)](https://github.com/thenovacreator "thenovacreator (16 commits)")[![fansanelli](https://avatars.githubusercontent.com/u/13917866?v=4)](https://github.com/fansanelli "fansanelli (3 commits)")[![Indigo744](https://avatars.githubusercontent.com/u/7137528?v=4)](https://github.com/Indigo744 "Indigo744 (3 commits)")[![thers](https://avatars.githubusercontent.com/u/213272?v=4)](https://github.com/thers "thers (2 commits)")[![milosh012](https://avatars.githubusercontent.com/u/1167990?v=4)](https://github.com/milosh012 "milosh012 (2 commits)")[![gitall](https://avatars.githubusercontent.com/u/9973818?v=4)](https://github.com/gitall "gitall (1 commits)")[![netsnatch](https://avatars.githubusercontent.com/u/11537020?v=4)](https://github.com/netsnatch "netsnatch (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![kaperys](https://avatars.githubusercontent.com/u/7786586?v=4)](https://github.com/kaperys "kaperys (1 commits)")[![SilverFire](https://avatars.githubusercontent.com/u/4499203?v=4)](https://github.com/SilverFire "SilverFire (1 commits)")[![snipe](https://avatars.githubusercontent.com/u/197404?v=4)](https://github.com/snipe "snipe (1 commits)")[![jaketoolson](https://avatars.githubusercontent.com/u/612332?v=4)](https://github.com/jaketoolson "jaketoolson (1 commits)")[![kruglikdenis](https://avatars.githubusercontent.com/u/9932991?v=4)](https://github.com/kruglikdenis "kruglikdenis (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mahmut-fileupload/health.svg)

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

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[spiral/framework

Spiral, High-Performance PHP/Go Framework

2.0k1.8M57](/packages/spiral-framework)[shopware/storefront

Storefront for Shopware

684.2M148](/packages/shopware-storefront)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[bolt/core

🧿 Bolt Core

585142.5k54](/packages/bolt-core)

PHPackages © 2026

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