PHPackages                             antoninmasek/laravel-max-upload-size-rule - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. antoninmasek/laravel-max-upload-size-rule

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

antoninmasek/laravel-max-upload-size-rule
=========================================

Adds Rule::file()-&gt;maxUploadSize() validation rule, which will validate filesize against `upload\_max\_filesize` php.ini setting

0.1.0(1y ago)310MITPHPPHP ^8.2CI failing

Since Jun 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/antoninmasek/laravel-max-upload-size-rule)[ Packagist](https://packagist.org/packages/antoninmasek/laravel-max-upload-size-rule)[ Docs](https://github.com/antoninmasek/laravel-max-upload-size-rule)[ RSS](/packages/antoninmasek-laravel-max-upload-size-rule/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (4)Dependencies (10)Versions (5)Used By (0)

Easily validate uploaded file size against `upload_max_filesize` php.ini setting
================================================================================

[](#easily-validate-uploaded-file-size-against-upload_max_filesize-phpini-setting)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b365a168bfd89ecd74ac6f8c5267672920bc333474c7207de56dff591245b598/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e746f6e696e6d6173656b2f6c61726176656c2d6d61782d75706c6f61642d73697a652d72756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/antoninmasek/laravel-max-upload-size-rule)[![Total Downloads](https://camo.githubusercontent.com/9241c40ca8b7b32ed7e33312650b5c0b15b2f96763ce556d8094aefc3c483f1c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e746f6e696e6d6173656b2f6c61726176656c2d6d61782d75706c6f61642d73697a652d72756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/antoninmasek/laravel-max-upload-size-rule)

On a few projects I've worked on, I noticed, that quite often we want to allow the max file size to be the same as our setting inside php.ini. Over time the value inside php.ini might change due to different requirements, but the validation rules usually stay the same until some user hits the rule and it prevents them from proceeding.

Thanks to this rule the max file size is automatically loaded based on the current php.ini setting hence it stays in sync.

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

[](#installation)

You can install the package via composer:

```
composer require antoninmasek/laravel-max-upload-size-rule
```

Basic usage
-----------

[](#basic-usage)

```
Validator::make(['file', $file], [Rule::file()->maxUploadSize()]);
Validator::make(['file', $file], [new MaxUploadSizeRule()]);
```

### Files larger than `max_upload_size`

[](#files-larger-than-max_upload_size)

Please note, that if the file is larger than `max_upload_size`, then you will receive the following error message: "The file failed to upload.". The reason is, that even if you try to inspect the uploaded file you will find out, that it has an error and is not uploaded, because it exceeds the limit.

### Files larger than `post_max_size`

[](#files-larger-than-post_max_size)

In this case, Laravel will throw an exception. In production, you might see "413 Content Too Large" and in debug mode, you would see "PostTooLargeException".

### Why use the rule then

[](#why-use-the-rule-then)

As mentioned above - thanks to this you will have the max allowed filesize in sync with the `php.ini`, so it basically means you are using the existing max rule, but it always uses the current setting based on `php.ini`. In all other ways, it behaves exactly like the max rule.

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Antonin Masek](https://github.com/antoninmasek)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance48

Moderate activity, may be stable

Popularity8

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

Total

4

Last Release

388d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8faef5fac979c7f7fa3622af216db9734384499fa3890e62e9f6e97b421b204f?d=identicon)[antoninmasek](/maintainers/antoninmasek)

---

Top Contributors

[![antoninmasek](https://avatars.githubusercontent.com/u/31475951?v=4)](https://github.com/antoninmasek "antoninmasek (18 commits)")

---

Tags

laravelAntonin Maseklaravel-max-upload-size-rule

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/antoninmasek-laravel-max-upload-size-rule/health.svg)

```
[![Health](https://phpackages.com/badges/antoninmasek-laravel-max-upload-size-rule/health.svg)](https://phpackages.com/packages/antoninmasek-laravel-max-upload-size-rule)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M101](/packages/dedoc-scramble)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.9k3](/packages/defstudio-telegraph)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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