mezon-security: Validate uploaded files using multiple rules

Recommend this page to a friend!
  Info   View files Documentation   View files View files (15)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-07-21 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 40 All time: 9,928 This week: 259Up
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: 16 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 1x

Details

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  
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  /  Tests  
File Role Description
Files folder imageres (1 file)
  Plain text file SecurityRulesUnitTest.php Class Class source

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

  Files folder image Files  /  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  /  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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:40
This week:0
All time:9,928
This week:259Up

For more information send a message to info at phpclasses dot org.