\Field\UtilityFileToolbox

FileToolbox class for handling files related tasks.

A set of utility methods related to files, such as bytesToSize(), fileIcon(), etc.

Summary

Methods
Properties
Constants
formatter()
bytesToSize()
fileIcon()
fileIconMap()
ext()
removeExt()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

formatter()

formatter(\Cake\View\View $view, \Field\Model\Entity\Field $field) : string

Renders the given custom field.

Parameters

\Cake\View\View $view

Instance of view class

\Field\Model\Entity\Field $field

The field to be rendered

Returns

string —

HTML code

bytesToSize()

bytesToSize(integer $bytes, integer $precision) : string

Gets a translated string representation of the size.

Parameters

integer $bytes

Size to convert given in bytes units

integer $precision

Decimal precision

Returns

string —

Human-readable size, e.g. 1 KB, 36.8 MB, etc

fileIcon()

fileIcon(string $mime, mixed $iconsDirectory) : mixed

Creates a path to the icon for a file mime.

Parameters

string $mime

File mime type

mixed $iconsDirectory

A path to a directory of icons to be used for files. Defaults to built-in icons directory (Field/webroot/img/file-icons/)

Returns

mixed —

A string for the icon file name, or false if an appropriate icon could not be found

fileIconMap()

fileIconMap(string $mime) : string

Determine the generic icon MIME package based on a file's MIME type.

Parameters

string $mime

File mime type

Returns

string —

The generic icon MIME package expected for this file

ext()

ext(string $fileName) : string

Get file extension.

Parameters

string $fileName

File name, including its extension. e.g.: my-file.docx

Returns

string —

File extension without the ending DOT and lowercased, e.g. pdf, jpg, png, etc. If no extension is found an empty string will be returned

removeExt()

removeExt(string $fileName) : string

Remove file extension.

Parameters

string $fileName

File name, including its extension. e.g. my-file.docx, myFile.DoCX, etc

Returns

string —

File name without extension, e.g. my-file, myFile, etc