All Projects → orkhanahmadov → Laravel Zip Validator

orkhanahmadov / Laravel Zip Validator

Licence: mit
Laravel ZIP file content validator

Projects that are alternatives of or similar to Laravel Zip Validator

Validation Composite
Allows uniting of several validation rules into single one for easy re-usage
Stars: ✭ 159 (+32.5%)
Mutual labels:  validation, validator, laravel
Credit Card
Credit Card Validation
Stars: ✭ 150 (+25%)
Mutual labels:  validation, validator, laravel
Validation
🔒 Laravel farsi/persian validation
Stars: ✭ 142 (+18.33%)
Mutual labels:  validation, validator, laravel
Validation
The power of Respect Validation on Laravel
Stars: ✭ 188 (+56.67%)
Mutual labels:  validation, validator, laravel
Govalidator
Validate Golang request data with simple rules. Highly inspired by Laravel's request validation.
Stars: ✭ 969 (+707.5%)
Mutual labels:  validation, validator
Laravel Vue Validator
Simple package to display error in vue from laravel validation
Stars: ✭ 32 (-73.33%)
Mutual labels:  validation, laravel
Validator
Client-side javascript validator library ports from Laravel 5.2
Stars: ✭ 35 (-70.83%)
Mutual labels:  validation, laravel
Is
Micro check library in Golang.
Stars: ✭ 61 (-49.17%)
Mutual labels:  validation, validator
Validating
Automatically validating Eloquent models for Laravel
Stars: ✭ 906 (+655%)
Mutual labels:  validation, laravel
Laravel5 Genderize Api Client
Laravel 5 client for the Genderize.io API
Stars: ✭ 47 (-60.83%)
Mutual labels:  validation, laravel
Inspector
A tiny class validation library.
Stars: ✭ 64 (-46.67%)
Mutual labels:  validation, validator
Ismailfine
A simple (but correct) library for validating email addresses. Supports mail addresses as defined in rfc5322 as well as the new Internationalized Mail Address standards (rfc653x). Based on https://github.com/jstedfast/EmailValidation
Stars: ✭ 9 (-92.5%)
Mutual labels:  validation, validator
Grpc Dotnet Validator
Simple request message validator for grpc.aspnet
Stars: ✭ 25 (-79.17%)
Mutual labels:  validation, validator
Validator
A tool to validate text inside TextInputLayout
Stars: ✭ 117 (-2.5%)
Mutual labels:  validation, validator
Cti Stix Validator
OASIS TC Open Repository: Validator for STIX 2.0 JSON normative requirements and best practices
Stars: ✭ 24 (-80%)
Mutual labels:  validation, validator
Laravel Smart
Automatic Migrations, Validation and More
Stars: ✭ 48 (-60%)
Mutual labels:  validation, laravel
Unicorn
Unicorn - W3C's Unified Validator
Stars: ✭ 70 (-41.67%)
Mutual labels:  validation, validator
Schemasafe
A reasonably safe JSON Schema validator with draft-04/06/07/2019-09 support.
Stars: ✭ 67 (-44.17%)
Mutual labels:  validation, validator
Form Object
Form object to use with Vue components for sending data to a Laravel application using axios.
Stars: ✭ 73 (-39.17%)
Mutual labels:  validation, laravel
Ngx Dynamic Form Builder
FormBuilder + class-transformer + class-validator = dynamic form group builder for Angular10+
Stars: ✭ 93 (-22.5%)
Mutual labels:  validation, validator

Laravel ZIP file validator

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.

Requirements

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

Installation

You can install the package via composer:

composer require orkhanahmadov/laravel-zip-validator

Usage

Use ZipContent rule with list of required files.

use Orkhanahmadov\ZipValidator\Rules\ZipContent;

public function rules()
{
    return [
        'file' => [
            'required',
            'file',
            'mimes:zip',
            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);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].