Laravel ZIP file content validator

1.9.0 2022-04-08 10:47 UTC

This package is auto-updated.

Last update: 2022-11-08 12:20:43 UTC


Buy us a tree Latest Stable Version Latest Unstable Version Total Downloads GitHub license

Build Status Test Coverage Maintainability Quality Score StyleCI

Custom Laravel validation rule for checking ZIP file content.


  • Laravel 6 or higher
  • PHP 7.2 or higher with zip extension enabled


You can install the package via composer:

composer require orkhanahmadov/laravel-zip-validator


Use ZipContent rule with list of required files.

use Orkhanahmadov\ZipValidator\Rules\ZipContent;

public function rules()
    return [
        'file' => [
            new ZipContent('thumb.jpg', 'assets/logo.png'),

Pass list of required files/folders to the constructor of the validator.

You can pass files as different constructor arguments or as array. If files are nested inside folders, pass relative path to file.

Validator will fail if any of the passed files does not exist in ZIP archive.

Validating maximum file size

Validator also allows checking maximum size of each file inside ZIP archive.

Simply pass file name as array key and maximum size as value:

new ZipContent(['thumb.jpg' => 100000]);

Validator in above example will look for thumb.jpg file with maximum size of 100000 bytes (100KB).

You can also mix multiple files with name-only or name+size validation:

new ZipContent(['thumb.jpg' => 100000, 'logo.png']);

Multiple files with "OR" validation

You can also pass multiple files with | symbol, if any of them exist in ZIP file validator will succeed.

new ZipContent('thumb.jpg|thumb.png|thumb.svg');

Validator in above example will look if thumb.jpg or thumb.png or thumb.svg file exists in ZIP.

Of course, you can also validate file size with "OR" validation:

new ZipContent(['thumb.jpg|thumb.png' => 100000]);

Above example will look if thumb.jpg or thumb.png file exists in ZIP and its file size is not bigger than 100000 bytes (100KB).

Important to keep in mind that when using "OR" validation with additional file size validation, validator will compare file size with the first matching element in ZIP archive.

Rejecting empty files

By default, validator only checks if file with given name exists, it will return true even if file with matching name is empty (has size of 0 bytes).

You can pass array of files as first argument and false as second argument to constructor if you want validator to reject files with 0 bytes.

new ZipContent(['thumb.jpg', 'style.css'], false);


composer test


Please see CHANGELOG for more information what has changed recently.


Please see CONTRIBUTING for details.


If you discover any security related issues, please email ahmadov90@gmail.com instead of using the issue tracker.



The MIT License (MIT). Please see License File for more information.