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

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

gravitypdf/upload
=================

Handle file uploads with extensible validation and storage strategies

3.1.0(2mo ago)518.7k↓30%3[3 issues](https://github.com/GravityPDF/Upload/issues)MITPHPPHP ^7.3 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

Since Sep 10Pushed 3y agoCompare

[ Source](https://github.com/GravityPDF/Upload)[ Packagist](https://packagist.org/packages/gravitypdf/upload)[ Docs](https://github.com/gravitypdf/upload)[ RSS](/packages/gravitypdf-upload/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (12)Used By (0)

Upload
======

[](#upload)

[![codecov](https://camo.githubusercontent.com/eea8d28683041850fe3d49693d5047228ec48e7b808fbe5de1be926af46e0072/68747470733a2f2f636f6465636f762e696f2f67682f477261766974795044462f55706c6f61642f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/GravityPDF/Upload)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)

This component simplifies file validation and uploading.

**Why was this library forked?**

- Original library was abandoned (untouched since 2018)
- Adjusted namespace from \\Upload to \\GravityPdf\\Upload
- Bumped minimum PHP version to 7.3+
- Sanitized filename and extension, and add UTF-8 filename support
- Strict type checking
- Added `FileSystem::getDirectory()` and `FileInfo::setNameWithExtension()` methods
- Included unreleased code from upstream repo
- PSR-12 Code Formatting
- Automated tools: PHPUnit, PHPStan, PHPCS, and PHP Syntax Checker

TODO: [PSR-7 and PSR-17 support (help wanted)](https://github.com/GravityPDF/Upload/issues/8)

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

[](#installation)

```
composer require gravitypdf/upload

```

Usage
-----

[](#usage)

Assume a file is uploaded with this HTML form:

```

```

When the HTML form is submitted, the server-side PHP code can validate and upload the file like this:

```
$storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory');
// To override existing files when uploading, pass `true` as the second parameter
// $storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory', true);
$file = new \GravityPdf\Upload\File('foo', $storage);

// Validate file upload
// MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml
$file->addValidations([
    // Ensure file is of type "image/png"
    new \GravityPdf\Upload\Validation\Mimetype('image/png'),
    new \GravityPdf\Upload\Validation\Extension('png'),

    //You can also add multi mimetype validation or extensions
    //new \GravityPdf\Upload\Validation\Mimetype(['image/png', 'image/gif'])
    //new \GravityPdf\Upload\Validation\Extension(['png', 'gif']),

    // Ensure file is no larger than 5M (use "B", "K", M", or "G")
    new \GravityPdf\Upload\Validation\Size('5M'),
]);

// Access data about the file
// If upload accepts multiple files an array will be returned for each of these
$data = [
    'name' => $file->getNameWithExtension(),
    'extension' => $file->getExtension(),
    'mime' => $file->getMimetype(),
    'size' => $file->getSize(),
    'md5' => $file->getMd5(),
    'dimensions' => $file->getDimensions(),
];

// If you have an upload field that accepts multiple files you can access each file's info individually
$firstFileName = $file[0]->getNameWithExtension();
if(isset($file[1])) {
    $secondFileName = $file[1]->getNameWithExtension();
}

// or loop over all files for this key
foreach($file as $i => $upload) {
    $name = $upload->getNameWithExtension();
    $upload->setName('file-'.$i);
}

// Try to upload file(s)
try {
    // Success!
    $file->upload();
} catch (\Exception $e) {
    // Validation errors
    $errors = $file->getErrors();
    if(count($errors) === 0) {
        // Failed for another reason, like the file already exists
        $error = $e->getMessage();
    }
}
```

Authors
-------

[](#authors)

- [Josh Lockhart](https://github.com/codeguy)
- [Gravity PDF](https://github.com/GravityPDF)

License
-------

[](#license)

MIT Public License

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

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

Recently: every ~1157 days

Total

10

Last Release

69d ago

Major Versions

1.3.2 → 2.0.02022-07-06

2.0.0 → 3.0.02022-07-07

PHP version history (4 changes)1.0.0PHP &gt;=5.3.0

2.0.0PHP ^7.3 || ^8.0

3.0.1PHP ^7.3 || ~8.0.0 || ~8.1.0 || ~8.2.0

3.1.0PHP ^7.3 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/04f0b4e5631a83cbcbccf0e952552fd44072bacd6334155e356464292c30e68a?d=identicon)[jakejackson1](/maintainers/jakejackson1)

---

Top Contributors

[![jakejackson1](https://avatars.githubusercontent.com/u/2918419?v=4)](https://github.com/jakejackson1 "jakejackson1 (39 commits)")[![scottrobertson](https://avatars.githubusercontent.com/u/68361?v=4)](https://github.com/scottrobertson "scottrobertson (16 commits)")[![brandonsavage](https://avatars.githubusercontent.com/u/197889?v=4)](https://github.com/brandonsavage "brandonsavage (10 commits)")[![Sentence](https://avatars.githubusercontent.com/u/716852?v=4)](https://github.com/Sentence "Sentence (3 commits)")[![DavidePastore](https://avatars.githubusercontent.com/u/1949364?v=4)](https://github.com/DavidePastore "DavidePastore (3 commits)")[![nikeee](https://avatars.githubusercontent.com/u/4068864?v=4)](https://github.com/nikeee "nikeee (3 commits)")[![karimzah](https://avatars.githubusercontent.com/u/9151066?v=4)](https://github.com/karimzah "karimzah (1 commits)")[![Kertudex](https://avatars.githubusercontent.com/u/3914881?v=4)](https://github.com/Kertudex "Kertudex (1 commits)")[![camilopayan](https://avatars.githubusercontent.com/u/104237?v=4)](https://github.com/camilopayan "camilopayan (1 commits)")[![OmarElgabry](https://avatars.githubusercontent.com/u/9262504?v=4)](https://github.com/OmarElgabry "OmarElgabry (1 commits)")[![pabloleone](https://avatars.githubusercontent.com/u/2090437?v=4)](https://github.com/pabloleone "pabloleone (1 commits)")[![reinink](https://avatars.githubusercontent.com/u/882133?v=4)](https://github.com/reinink "reinink (1 commits)")[![codyphobe](https://avatars.githubusercontent.com/u/207072?v=4)](https://github.com/codyphobe "codyphobe (1 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (1 commits)")

---

Tags

validationfileupload

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[delight-im/file-upload

Simple and convenient file uploads — secure by default

7210.7k2](/packages/delight-im-file-upload)[liyunfang/yii2-upload-behavior

Upload behavior for Yii 2

161.7k](/packages/liyunfang-yii2-upload-behavior)

PHPackages © 2026

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