2017 © Pedro Peláez
 

library image-safe

Ensure a file is a valid image with a set of specifications.

image

motters/image-safe

Ensure a file is a valid image with a set of specifications.

  • Sunday, June 26, 2016
  • by motters
  • Repository
  • 0 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Image Safe

This is used when you want to verify file uploads that are restricted to images only!, (*1)

Basic verification provided by main stream frameworks is not sufficient and is insecure. Which is the reason for myself providing this package to the community., (*2)

Use

public function uploadImageSafe()
{
    //Start image safe validation
    $v = new Motters\ImageSafe\ImageSafe();

    //Set the rules for image safe
    $validationRules = [
        //Types of mimes that are allowed 
        'Mimes', // Optional settings ['allowed'=>['image/jpeg; charset=binary', 'image/jpg; charset=binary']]

        //Make sure file name is aplha numerical (Files should always be renamed anway!)
        'FileName', // Optional settings ['allowed'=>['-','_'], 'maximumCharacters'=>'100', 'minimumCharacters'=>'1']

        //Minimum and maxium size of file image (Minimum file size will help stop denial of service attacks )
        'FileSize', // Optional settings ['maximum'=>'2097152', 'minimum'=>'10240']

        //Make sure the image has some valid and set dumensions
        'DimensionSize', // Optional settings ['height'=>'1024', 'width'=>'768']

        //Searches for elements in the images mimes that could potential be arbatry code, this is very beta!
        'Characters', // ['unbanCharacters'=>['<?'], 'addbanCharacters'=>['<?'], 'addremoveCharacters'=>['<?'], 'unremoveCharacters'=>['<?']]

        //Makes sure that the WHOLE image extention meets the below allowed white list 
        'FileExtension', // Optional settings ['allowed'=>['jpeg','jpeg.php']]
    ];

    //Has validation passed or failed
    if( $v->validate( $_FILES["image"], $validationRules ) )
    {
        //Passed upload image (Laravel Only Example)
        $file = Input::file('image');
        $fileName = $file->getClientOriginalName();
        $fileDest = 'img';
        $upload = Input::file('image')->move($fileDest, $fileName);

        return Redirect::to('');
    }

    //Failed show some error message
    dd('validation failed');
}

Status

Active development and first stable release to be expected by 20/1/2016, (*3)

Security

If you find a way to bypass this package's protection please open an issue on Github or email me at sammottley@gmail.com., (*4)

ToDo

Tidy code, write tests, provide demonstration of why this library is necessary., (*5)

Special Thanks To

Nobody at the moment., (*6)

The Versions

26/06 2016

dev-master

9999999-dev

Ensure a file is a valid image with a set of specifications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

file validation upload image