class upload

File upload class Init class (all parameters optional and able to be set/overwritten separately) - scope is global and valid for all uploads

Properties

array $allowed_extensions
protected array $disallowed_content
int $max_filesize
int $min_width
int $min_height
int $max_width
int $max_height
string $error_prefix
int $upload_timeout
protected filesystem_interface $filesystem
protected factory $factory
protected IniGetWrapper $php_ini
protected language $language
protected request_interface $request

Methods

__construct(filesystem_interface $filesystem, factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request)

Init file upload class.

reset_vars()

Reset vars

set_allowed_extensions(array $allowed_extensions)

Set allowed extensions

set_allowed_dimensions(int $min_width, int $min_height, int $max_width, int $max_height)

Set allowed dimensions

set_max_filesize(int $max_filesize)

Set maximum allowed file size

set_disallowed_content(array $disallowed_content)

Set disallowed strings

set_error_prefix(string $error_prefix)

Set error prefix

filespec|bool
handle_upload(string $type)

Handle upload based on type

string
assign_internal_error(string $errorcode)

Assign internal error

common_checks(filespec $file)

Perform common file checks

bool
valid_extension(filespec $file)

Check for allowed extension

bool
valid_dimensions(filespec $file)

Check for allowed dimension

bool
is_valid(string $form_name)

Check if form upload is valid

bool
valid_content(filespec $file)

Check for bad content (IE mime-sniffing)

static array
image_types()

Get image type/extension mapping

Details

at line 77
__construct(filesystem_interface $filesystem, factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request)

Init file upload class.

Parameters

filesystem_interface $filesystem
factory $factory

Files factory

language $language

Language class

IniGetWrapper $php_ini

ini_get() wrapper

request_interface $request

Request class

at line 89
reset_vars()

Reset vars

at line 105
upload set_allowed_extensions(array $allowed_extensions)

Set allowed extensions

Parameters

array $allowed_extensions

Allowed file extensions

Return Value

upload

This instance of upload

at line 125
upload set_allowed_dimensions(int $min_width, int $min_height, int $max_width, int $max_height)

Set allowed dimensions

Parameters

int $min_width

Minimum image width

int $min_height

Minimum image height

int $max_width

Maximum image width

int $max_height

Maximum image height

Return Value

upload

This instance of upload

at line 142
upload set_max_filesize(int $max_filesize)

Set maximum allowed file size

Parameters

int $max_filesize

Maximum file size

Return Value

upload

This instance of upload

at line 159
upload set_disallowed_content(array $disallowed_content)

Set disallowed strings

Parameters

array $disallowed_content

Disallowed content

Return Value

upload

This instance of upload

at line 176
upload set_error_prefix(string $error_prefix)

Set error prefix

Parameters

string $error_prefix

Prefix for language variables of errors

Return Value

upload

This instance of upload

at line 191
filespec|bool handle_upload(string $type)

Handle upload based on type

Parameters

string $type

Upload type

Return Value

filespec|bool

A filespec instance if upload was successful, false if there were issues or the type is not supported

at line 209
string assign_internal_error(string $errorcode)

Assign internal error

Parameters

string $errorcode

Error code to assign

Return Value

string

Error string

at line 264
common_checks(filespec $file)

Perform common file checks

Parameters

filespec $file

Instance of filespec class

at line 300
bool valid_extension(filespec $file)

Check for allowed extension

Parameters

filespec $file

Instance of filespec class

Return Value

bool

True if extension is allowed, false if not

at line 313
bool valid_dimensions(filespec $file)

Check for allowed dimension

Parameters

filespec $file

Instance of filespec class

Return Value

bool

True if dimensions are valid or no constraints set, false if not

at line 338
bool is_valid(string $form_name)

Check if form upload is valid

Parameters

string $form_name

Name of form

Return Value

bool

True if form upload is valid, false if not

at line 353
bool valid_content(filespec $file)

Check for bad content (IE mime-sniffing)

Parameters

filespec $file

Instance of filespec class

Return Value

bool

True if content is valid, false if not

at line 363
static array image_types()

Get image type/extension mapping

Return Value

array

Array containing the image types and their extensions