class filespec_storage

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 bool $file_moved
protected bool $local
protected bool $class_initialized
array $error
upload $upload
protected FastImageSize $imagesize
protected language $language
protected plupload|null $plupload
protected guesser|null $mimetype_guesser

Methods

__construct(language $language, FastImageSize $imagesize, 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($storage)

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(storage $storage, bool $overwrite = false, bool $skip_image_check = false)

Move file to destination folder

bool
additional_checks()

Performing additional checks

Details

at line 89
__construct(language $language, FastImageSize $imagesize, guesser $mimetype_guesser = null, plupload $plupload = null)

File upload class

Parameters

language $language

Language

FastImageSize $imagesize

Imagesize class

guesser $mimetype_guesser

Mime type guesser

plupload $plupload

Plupload

at line 104
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 147
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 159
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 171
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 187
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 235
mixed get(string $property)

Get property from file object

Parameters

string $property

Name of property

Return Value

mixed

Content of property

at line 250
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 260
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 280
remove($storage)

Remove file

Parameters

$storage

at line 299
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 318
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 340
int get_filesize(string $filename)

Get file size

Parameters

string $filename

File name of file to check

Return Value

int

File size

at line 353
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 387
bool move_file(storage $storage, bool $overwrite = false, bool $skip_image_check = false)

Move file to destination folder

Parameters

storage $storage
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

Return Value

bool

True if file was moved, false if not

at line 482
bool additional_checks()

Performing additional checks

Return Value

bool

False if issue was found, true if not