2017 © Pedro Peláez
 

library bulletproof

A simple and secure PHP image uploader

image

samayo/bulletproof

A simple and secure PHP image uploader

  • Sunday, June 24, 2018
  • by samayo
  • Repository
  • 33 Watchers
  • 262 Stars
  • 2,919 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 48 Forks
  • 1 Open issues
  • 19 Versions
  • 8 % Grown

The README.md

BULLETPROOF Test

Latest Stable Version Total Downloads Scrutinizer Code Quality License, (*1)

Bulletproof is a single-class PHP library to upload images securely., (*2)

Installation

Install using git, (*3)

$ git clone https://github.com/samayo/bulletproof.git

Install using Composer, (*4)

$ composer require samayo/bulletproof:5.0.*

Or download it manually in a ZIP format, (*5)

Usage

To quickly upload images, use the following HTML & PHP code:, (*6)

<form method="POST" enctype="multipart/form-data">
  <input type="hidden" name="MAX_FILE_SIZE" value="1000000"/>
  <input type="file" name="pictures" accept="image/*"/>
  <input type="submit" value="upload"/>
</form>

```php require_once "path/to/bulletproof.php";, (*7)

$image = new Bulletproof\Image($_FILES);, (*8)

if($image["pictures"]){ $upload = $image->upload();, (*9)

if($upload){ echo $upload->getPath(); // uploads/cat.gif }else{ echo $image->getError(); } }, (*10)

For more options or configurations, check the following examples:


Configs
-----

#### Setting Properties
Methods to set restriction on the image name, size, type, etc.. to upload
```php  
// To provide a name for the image. If unused, image name will be auto-generated.
$image->setName($name);

// To set the min/max image size to upload (in bytes)
$image->setSize($min, $max);

// To define a list of allowed image types to upload
$image->setMime(array('jpeg', 'gif'));

// To set the max image height/width to upload (limit in pixels)
$image->setDimension($width, $height);

// To create a folder name to store the uploaded image, with optional chmod permission
$image->setStorage($folderName, $optionalPermission);

Getting Properties

Methods to retrieve image data before/after upload., (*11)

// To get the image name
$image->getName();

// To get the image size (in bytes)
$image->getSize();

// To get the image mime (extension)
$image->getMime();

// To get the image width in pixels
$image->getWidth();

// To get the image height in pixels
$image->getHeight();

// To get image location (folder where images are uploaded)
$image->getStorage();

// To get the full image path. ex 'images/logo.jpg'
$image->getPath();

// To get the json format value of all the above information
$image->getJson();

Extended Configuration Usage

How to use the property setters and getters., (*12)

$image = new Bulletproof\Image($_FILES);

$image->setName("samayo")
      ->setMime(["gif"])
      ->setStorage(__DIR__ . "/avatars");

if($image["pictures"]){
  if($image->upload()){
    echo $image->getName(); // samayo   
    echo $image->getMime(); // gif
    echo $image->getStorage(); // avatars
    echo $image->getPath(); // avatars/samayo.gif
  }
}

Image Manipulation

To crop, resize or watermak images, use functions stored in src/utils, (*13)

Creating custom errors

Use php exceptions to define custom error responses, (*14)

if($image['pictures']){
  try {
    if($image->getMime() !== 'png'){
      throw new \Exception('Only PNG image types are allowed');
    }

    // check size, width, height...

    if(!$image->upload()){
      throw new \Exception($image->getError());
    } else {
      echo $image->getPath();
    }

  } catch (\Exception $e){
    echo "Error " . $e->getMessage();
  }
}

What makes this secure?

  • Uses exif_imagetype() to get the true image mime (.extension)
  • Uses getimagesize() to check if image has a valid height / width in pixels.
  • Sanitized images names, strict folder permissions and more...

License: MIT

The Versions

24/06 2018

dev-master

9999999-dev http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image simple

24/06 2018

v4.0.1

4.0.1.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image simple

23/06 2018

v4.0.0

4.0.0.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image simple

08/02 2018

dev-prettify

dev-prettify http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image simple

22/10 2017

3.2.0

3.2.0.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image simple

18/09 2017

3.0.2

3.0.2.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image

14/09 2017

3.0.1

3.0.1.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image

24/08 2017

dev-dev

dev-dev http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image

29/07 2017

3.0.0

3.0.0.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-exif *

 

The Development Requires

by Avatar samayo

security upload image

24/03 2017

2.0.5

2.0.5.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar samayo

security upload image

24/03 2017

2.0.4

2.0.4.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar samayo

security upload image

10/03 2017

dev-fix

dev-fix http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar samayo

security upload image

10/01 2017

2.0.3

2.0.3.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar samayo

security upload image

10/01 2017

2.0.2

2.0.2.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar samayo

security upload image

04/08 2015

2.0.1

2.0.1.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar samayo

security upload image

01/06 2015

2.0.0

2.0.0.0 http://github.com/samayo/bulletproof

A simple and secure PHP image uploader

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar samayo

security upload image

24/06 2014

1.4

1.4.0.0 http://github.com/bivoc/BulletProof

PHP Secure Image Uploader, Cropper, Watermark, and Image Reisizing tool

  Sources   Download

public domain

The Requires

  • php >=5.3.0

 

by Simon_QD

upload image resize crop watermark

15/06 2014

1.2

1.2.0.0 http://github.com/bivoc/BulletProof

PHP Secure Image Uploader, Cropper, Watermark, and Image Reisizing tool

  Sources   Download

public domain

The Requires

  • php >=5.3.0

 

by Simon_eQ

upload image resize crop watermark

24/05 2014

1.0

1.0.0.0 http://github.com/bivoc/BulletProof

PHP Secure Image Uploader, Cropper, Watermark, and Image Reisizing tool

  Sources   Download

public domain

The Requires

  • php >=5.3.0

 

by Simon_eQ

upload image crop watermark