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
protected factory $factory
protected IniGetWrapper $php_ini
protected language $language
protected request_interface $request

Methods

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

Init file upload class.

reset_vars()

Reset vars

set_allowed_extensions(array|bool $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|bool $disallowed_content)

Set disallowed strings

set_error_prefix(string $error_prefix)

Set error prefix

handle_upload(string $type)

Handle upload based on type

string
assign_internal_error(string $errorcode)

Assign internal error

common_checks(filespec_storage $file)

Perform common file checks

bool
valid_extension(filespec_storage $file)

Check for allowed extension

bool
valid_dimensions(filespec_storage $file)

Check for allowed dimension

bool
is_valid(string $form_name)

Check if form upload is valid

bool
valid_content(filespec_storage $file)

Check for bad content (IE mime-sniffing)

static array
image_types()

Get image type/extension mapping

Details

at line 69
__construct(factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request)

Init file upload class.

Parameters

factory $factory

Files factory

language $language

Language class

IniGetWrapper $php_ini

ini_get() wrapper

request_interface $request

Request class

at line 80
reset_vars()

Reset vars

at line 96
upload set_allowed_extensions(array|bool $allowed_extensions)

Set allowed extensions

Parameters

array|bool $allowed_extensions

Allowed file extensions

Return Value

upload

This instance of upload

at line 116
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 133
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 150
upload set_disallowed_content(array|bool $disallowed_content)

Set disallowed strings

Parameters

array|bool $disallowed_content

Disallowed content

Return Value

upload

This instance of upload

at line 167
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 182
filespec_storage|bool handle_upload(string $type)

Handle upload based on type

Parameters

string $type

Upload type

Return Value

filespec_storage|bool

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

at line 200
string assign_internal_error(string $errorcode)

Assign internal error

Parameters

string $errorcode

Error code to assign

Return Value

string

Error string

at line 255
common_checks(filespec_storage $file)

Perform common file checks

Parameters

filespec_storage $file

Instance of filespec class

at line 291
bool valid_extension(filespec_storage $file)

Check for allowed extension

Parameters

filespec_storage $file

Instance of filespec class

Return Value

bool

True if extension is allowed, false if not

at line 304
bool valid_dimensions(filespec_storage $file)

Check for allowed dimension

Parameters

filespec_storage $file

Instance of filespec class

Return Value

bool

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

at line 329
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 344
bool valid_content(filespec_storage $file)

Check for bad content (IE mime-sniffing)

Parameters

filespec_storage $file

Instance of filespec class

Return Value

bool

True if content is valid, false if not

at line 354
static array image_types()

Get image type/extension mapping

Return Value

array

Array containing the image types and their extensions