phpBB API Documentation
Class

phpbb\files\upload

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
int $max_filesize
int $min_width
int $min_height
int $max_width
int $max_height
string $error_prefix
int $upload_timeout

Methods

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

Init file upload class.

reset_vars()

Reset vars

upload set_allowed_extensions(array $allowed_extensions)

Set allowed extensions

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

Set allowed dimensions

upload set_max_filesize(int $max_filesize)

Set maximum allowed file size

upload set_disallowed_content(array $disallowed_content)

Set disallowed strings

upload 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
public __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
public reset_vars()

Reset vars

at line 105
public 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
public 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
public 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
public 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
public 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
public 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
public string assign_internal_error(string $errorcode)

Assign internal error

Parameters

string $errorcode Error code to assign

Return Value

string Error string

at line 264
public common_checks(filespec $file)

Perform common file checks

Parameters

filespec $file Instance of filespec class

at line 300
public 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
public 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
public 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
public 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 public array image_types()

Get image type/extension mapping

Return Value

array Array containing the image types and their extensions