class filespec

deprecated 4.0.0 Use phpbb\files\filespec_storage instead

Responsible for holding all file relevant information, as well as doing file-specific operations.

The fileupload fileupload class can be used to upload several files, each of them being this object to operate further on.

Properties

protected string $filename
protected string $realname
protected string $uploadname
protected string $mimetype
protected string $extension
protected int $filesize
protected int $width
protected int $height
protected array $image_info
protected string $destination_file
protected string $destination_path
protected bool $file_moved
protected bool $local
protected bool $class_initialized
array $error
upload $upload
protected filesystem_interface $filesystem
protected IniGetWrapper $php_ini
protected FastImageSize $imagesize
protected language $language
protected string $phpbb_root_path
protected plupload|null $plupload
protected guesser|null $mimetype_guesser

Methods

__construct(filesystem_interface $phpbb_filesystem, language $language, IniGetWrapper $php_ini, FastImageSize $imagesize, string $phpbb_root_path, guesser $mimetype_guesser = null, plupload $plupload = null)

File upload class

set_upload_ary(array $upload_ary)

Set upload ary

set_upload_namespace(upload $namespace)

Set the upload namespace

bool
init_error()

Check if class members were not properly initialised yet

set_error(mixed $error)

Set error in error array

clean_filename(string $mode = 'unique', string $prefix = '', string $user_id = '')

Cleans destination filename

mixed
get(string $property)

Get property from file object

bool
is_image()

Check if file is an image (mime type)

bool
is_uploaded()

Check if the file got correctly uploaded

remove()

Remove file

static string
get_extension(string $filename)

Get file extension

string
get_mimetype(string $filename)

Get mime type

int
get_filesize(string $filename)

Get file size

bool
check_content(array $disallowed_content)

Check the first 256 bytes for forbidden content

bool
move_file(string $destination, bool $overwrite = false, bool $skip_image_check = false, string|bool $chmod = false)

Move file to destination folder The phpbb_root_path variable will be applied to the destination path

bool
additional_checks()

Performing additional checks

Details

at line 106
__construct(filesystem_interface $phpbb_filesystem, language $language, IniGetWrapper $php_ini, FastImageSize $imagesize, string $phpbb_root_path, guesser $mimetype_guesser = null, plupload $plupload = null)

File upload class

Parameters

filesystem_interface $phpbb_filesystem

Filesystem

language $language

Language

IniGetWrapper $php_ini

ini_get() wrapper

FastImageSize $imagesize

Imagesize class

string $phpbb_root_path

phpBB root path

guesser $mimetype_guesser

Mime type guesser

plupload $plupload

Plupload

at line 124
filespec set_upload_ary(array $upload_ary)

Set upload ary

Parameters

array $upload_ary

Upload ary

Return Value

filespec

This instance of the filespec class

at line 167
filespec set_upload_namespace(upload $namespace)

Set the upload namespace

Parameters

upload $namespace

Instance of upload class

Return Value

filespec

This instance of the filespec class

at line 179
bool init_error()

Check if class members were not properly initialised yet

Return Value

bool

True if there was an init error, false if not

at line 191
filespec set_error(mixed $error)

Set error in error array

Parameters

mixed $error

Content for error array

Return Value

filespec

This instance of the filespec class

at line 207
clean_filename(string $mode = 'unique', string $prefix = '', string $user_id = '')

Cleans destination filename

Parameters

string $mode

Either real, unique, or unique_ext. Real creates a realname, filtering some characters, lowering every character. Unique creates a unique filename.

string $prefix

Prefix applied to filename

string $user_id

The user_id is only needed for when cleaning a user's avatar

at line 255
mixed get(string $property)

Get property from file object

Parameters

string $property

Name of property

Return Value

mixed

Content of property

at line 270
bool is_image()

Check if file is an image (mime type)

Return Value

bool

true if it is an image, false if not

at line 280
bool is_uploaded()

Check if the file got correctly uploaded

Return Value

bool

true if it is a valid upload, false if not

at line 300
remove()

Remove file

at line 315
static string get_extension(string $filename)

Get file extension

Parameters

string $filename

Filename that needs to be checked

Return Value

string

Extension of the supplied filename

at line 334
string get_mimetype(string $filename)

Get mime type

Parameters

string $filename

Filename that needs to be checked

Return Value

string

Mime type of supplied filename

at line 356
int get_filesize(string $filename)

Get file size

Parameters

string $filename

File name of file to check

Return Value

int

File size

at line 369
bool check_content(array $disallowed_content)

Check the first 256 bytes for forbidden content

Parameters

array $disallowed_content

Array containg disallowed content

Return Value

bool

False if disallowed content found, true if not

at line 406
bool move_file(string $destination, bool $overwrite = false, bool $skip_image_check = false, string|bool $chmod = false)

Move file to destination folder The phpbb_root_path variable will be applied to the destination path

Parameters

string $destination

Destination path, for example $config['avatar_path']

bool $overwrite

If set to true, an already existing file will be overwritten

bool $skip_image_check

If set to true, the check for the file to be a valid image is skipped

string|bool $chmod

Permission mask for chmodding the file after a successful move. The mode entered here reflects the mode defined by phpbb_chmod()

Return Value

bool

True if file was moved, false if not

at line 557
bool additional_checks()

Performing additional checks

Return Value

bool

False if issue was found, true if not