PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Alexey Dodonov   mezon-security   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: mezon-security
Validate uploaded files using multiple rules
Author: By
Last change:
Date: 3 years ago
Size: 1,866 bytes
 

Contents

Class file image Download

Security validations

Build Status Scrutinizer Code Quality codecov

Intro

Mezon provides set of classes wich will help you to validate data from front-end

Installation

Just print in console

composer require mezon/security

And that's all )

Files validations

Size validations

First of all you need to create validator for the file size:

use \Mezon\Security;

// here we set that file must not be greater then 2KB
$sizeValidator = new Validators\File\Size(2 * Validators\File\Size::KB);

Then you can run validation

$security = new SecurityRules();
$security->isUploadedFileValid('uploaded-file', $validators);

Here 'uploaded-file' is an index in the $_FILES array.

Mime-types validations

You can validate mime types of the uploading files. To do this construct special validator and pass a list of valid mime types to it's constructor

// here we set that file must not be greater then 2KB
$sizeValidator = new Validators\File\MymeType(['image/png', 'image/jpeg', 'image/jpg']);

And then call isUploadedFileValid like in the example above.

Image validators

You can use validators for the image size:

new Mezon\Security\Validators\File\ImageMaximumWidthHeight(<maximum width>, <maximum height>);

// and

new Mezon\Security\Validators\File\ImageMinimumWidthHeight(<minimum width>, <minimum height>);

I'll be very glad if you'll press "STAR" button )