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

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

lkt/file-upload
===============

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

1.0.2(3y ago)01701MITPHPPHP ^8.1

Since Dec 24Pushed 3y agoCompare

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

READMEChangelog (3)Dependencies (2)Versions (4)Used By (1)

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": {
    "gargron/fileupload": "~1.4.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 Validator\Simple('2M', ['image/png', 'image/jpg']);

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

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

// FileUploader itself
$fileupload = new \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 Validator\MimeTypeValidator(['image/png', 'image/jpg']),
        new 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 Validator\Simple('2M', ['image/png', 'image/jpg']);
```

- `MimeTypeValidator`

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

- `SizeValidator`

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

- `DimensionValidator`

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

$dimensionValidator = new 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($_FILES['files'], $_SERVER);
$filenamegenerator = new FileNameGenerator\Simple();
$fileupload->setFileNameGenerator($filenamegenerator);
```

- `Custom`

```
$customGenerator = new 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 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 FileNameGenerator\Random($length);
//Where $length is the maximum length of the generator random name
```

- `Simple`

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

- `Slug`

```
$slugGenerator = new 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(\File $file) {
    // Whoosh!
});
```

- `beforeValidation`

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

- `afterValidation`

```
$fileUploader->addCallback('afterValidation', function (\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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor3

3 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 ~15 days

Total

3

Last Release

1210d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0915bfa65bb0c27057b7043d2b423137915e107411dd1684630508f2df076291?d=identicon)[lkt](/maintainers/lkt)

---

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)")[![alphaibanez](https://avatars.githubusercontent.com/u/24976472?v=4)](https://github.com/alphaibanez "alphaibanez (10 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/lkt-file-upload/health.svg)

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

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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