PHP Classes

mezon-security: Validate uploaded files using multiple rules

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 51 All time: 10,677 This week: 206Up
Version License PHP version Categories
mezon-security 1.0MIT/X Consortium ...5PHP 5, Graphics, Files and Folders, V...
Description 

Author

This package can validate uploaded files using multiple rules.

It provides a main validation class for accessing files uploaded via Web forms.

Additional classes are provided to implement several types of validation. Currently it provides validation classes to:

- Check the size of files to accept only those within the limits
- Check the contents of files to accept only those of given MIME types
- Check the size of image files to accept only those with a given width or height.

Picture of Alexey Dodonov
  Performance   Level  
Name: Alexey Dodonov <contact>
Classes: 58 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 184954 in Russian Federation Russian Federation
Week rank: 200 Up8 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 13x

Documentation

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 )


  Files folder image Files (15)  
File Role Description
Files folder imageTests (1 file, 1 directory)
Files folder imageValidators (2 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Security.php Class Class source
Plain text file SecurityRules.php Class Class source

  Files folder image Files (15)  /  Tests  
File Role Description
Files folder imageres (1 file)
  Plain text file SecurityRulesUnitTest.php Class Class source

  Files folder image Files (15)  /  Tests  /  res  
File Role Description
  Accessible without login Image file test.png Data Auxiliary data

  Files folder image Files (15)  /  Validators  
File Role Description
Files folder imageFile (4 files)
  Plain text file AbstractValidator.php Class Class source
  Plain text file ValidatorInterface.php Class Class source

  Files folder image Files (15)  /  Validators  /  File  
File Role Description
  Plain text file ImageMaximumWidthHeight.php Class Class source
  Plain text file ImageMinimumWidthHeight.php Class Class source
  Plain text file MimeType.php Class Class source
  Plain text file Size.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:51
This week:0
All time:10,677
This week:206Up