PHP Class BulletProof\Image

Inheritance: implements ArrayAccess
ファイルを表示 Open project: samayo/bulletproof

Protected Properties

Property Type Description
$dimensions The max height and width image allowed
$fullPath The full image path (dir + image + mime)
$height The image height in pixels
$imageMimes list of known image types
$location The folder or image storage location
$mime The image mime type (extension)
$mimeTypes The mime types allowed for upload
$name The new image name, to be provided or will be generated.
$serialize A json format of all information about an image
$size The min and max image size allowed for upload (in bytes)
$width The image width in pixels

Public Methods

Method Description
__construct ( array $_files = [] )
getError ( ) : string | boolean Returns error string or false if no errors occurred
getFullPath ( ) : string Returns the full path of the image ex "location/image.mime"
getHeight ( ) : integer Returns the image height in pixels
getJson ( ) : string Returns a JSON format of the image width, height, name, mime .
getLocation ( ) : string Returns the storage / folder name
getMime ( ) : string Returns the image mime type
getName ( ) : string Returns the image name
getSize ( ) : integer Returns the image size in bytes
getWidth ( ) : integer Returns the image width
moveUploadedFile ( $tmp_name, $destination ) : boolean Final upload method to be called, isolated for testing purposes
offsetExists ( $offset )
offsetGet ( mixed $offset ) : boolean | mixed Gets array value \ArrayAccess
offsetSet ( $offset, $value ) array offset \ArrayAccess unused
offsetUnset ( $offset )
setDimension ( $maxWidth, $maxHeight ) Sets acceptable max image height and width
setLocation ( $dir = "bulletproof", integer $permission = 438 ) Creates a location for upload storage
setMime ( array $fileTypes ) Define a mime type for uploading
setName ( $isNameProvided = null ) Renames image
setSize ( $min, $max ) Define a min and max image size for uploading
upload ( ) Main upload method.

Protected Methods

Method Description
getImageMime ( $tmp_name ) : boolean | string Gets the real image mime type
uploadErrors ( $e ) Checks for the common upload errors

Method Details

__construct() public method

public __construct ( array $_files = [] )
$_files array represents the $_FILES array passed as dependancy

getError() public method

Returns error string or false if no errors occurred
public getError ( ) : string | boolean
return string | boolean

getFullPath() public method

Returns the full path of the image ex "location/image.mime"
public getFullPath ( ) : string
return string

getHeight() public method

Returns the image height in pixels
public getHeight ( ) : integer
return integer

getImageMime() protected method

Gets the real image mime type
protected getImageMime ( $tmp_name ) : boolean | string
$tmp_name string The upload tmp directory
return boolean | string

getJson() public method

..
public getJson ( ) : string
return string

getLocation() public method

Returns the storage / folder name
public getLocation ( ) : string
return string

getMime() public method

Returns the image mime type
public getMime ( ) : string
return string

getName() public method

Returns the image name
public getName ( ) : string
return string

getSize() public method

Returns the image size in bytes
public getSize ( ) : integer
return integer

getWidth() public method

Returns the image width
public getWidth ( ) : integer
return integer

moveUploadedFile() public method

Final upload method to be called, isolated for testing purposes
public moveUploadedFile ( $tmp_name, $destination ) : boolean
$tmp_name int the temporary location of the image file
$destination int upload destination
return boolean

offsetExists() public method

public offsetExists ( $offset )

offsetGet() public method

Gets array value \ArrayAccess
public offsetGet ( mixed $offset ) : boolean | mixed
$offset mixed
return boolean | mixed

offsetSet() public method

array offset \ArrayAccess unused
public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

setDimension() public method

Sets acceptable max image height and width
public setDimension ( $maxWidth, $maxHeight )
$maxWidth int max width value
$maxHeight int max height value

setLocation() public method

Creates a location for upload storage
public setLocation ( $dir = "bulletproof", integer $permission = 438 )
$dir string the folder name to create
$permission integer chmod permission

setMime() public method

Define a mime type for uploading
public setMime ( array $fileTypes )
$fileTypes array

setName() public method

Renames image
public setName ( $isNameProvided = null )

setSize() public method

Define a min and max image size for uploading
public setSize ( $min, $max )
$min int minimum value in bytes
$max int maximum value in bytes

upload() public method

This is where all the monkey business happens
public upload ( )

uploadErrors() protected method

Checks for the common upload errors
protected uploadErrors ( $e )
$e int error constant

Property Details

$dimensions protected_oe property

The max height and width image allowed
protected $dimensions

$fullPath protected_oe property

The full image path (dir + image + mime)
protected $fullPath

$height protected_oe property

The image height in pixels
protected $height

$imageMimes protected_oe property

list of known image types
protected $imageMimes

$location protected_oe property

The folder or image storage location
protected $location

$mime protected_oe property

The image mime type (extension)
protected $mime

$mimeTypes protected_oe property

The mime types allowed for upload
protected $mimeTypes

$name protected_oe property

The new image name, to be provided or will be generated.
protected $name

$serialize protected_oe property

A json format of all information about an image
protected $serialize

$size protected_oe property

The min and max image size allowed for upload (in bytes)
protected $size

$width protected_oe property

The image width in pixels
protected $width