trait UploadReceiver mixin FormField (View source)

Represents a form field which has an Upload() instance and can upload to a folder

Note that this trait expects to be applied to a {\SilverStripe\Forms\FormField} class

Properties

protected Upload $upload

Upload object (needed for validation and actually moving the temporary file created by PHP).

protected string $folderName

Partial filesystem path relative to /assets directory.

Methods

protected
constructUploadReceiver()

Bootstrap Uploadable field

public
getUpload()

Retrieves the Upload handler

public
$this
setUpload(Upload $upload)

Sets the upload handler

public
$this
setAllowedExtensions(array $rules)

Limit allowed file extensions. Empty by default, allowing all extensions.

public
$this
setAllowedFileCategories(string $category)

Limit allowed file extensions by specifying categories of file types.

public
array
getAllowedExtensions()

Returns list of extensions allowed by this field, or an empty array if there is no restriction

public
getValidator()

Get custom validator for this field

public
$this
setValidator(Upload_Validator $validator)

Set custom validator for this field

public
$this
setFolderName(string $folderName)

Sets the upload folder name

public
string
getFolderName()

Gets the upload folder name

Details

protected constructUploadReceiver()

Bootstrap Uploadable field

Upload getUpload()

Retrieves the Upload handler

Return Value

Upload

$this setUpload(Upload $upload)

Sets the upload handler

Parameters

Upload $upload

Return Value

$this

Self reference

$this setAllowedExtensions(array $rules)

Limit allowed file extensions. Empty by default, allowing all extensions.

To allow files without an extension, use an empty string. See File::$allowed_extensions to get a good standard set of extensions that are typically not harmful in a webserver context. See setAllowedMaxFileSize() to limit file size by extension.

Parameters

array $rules

List of extensions

Return Value

$this

$this setAllowedFileCategories(string $category)

Limit allowed file extensions by specifying categories of file types.

These may be 'image', 'image/supported', 'audio', 'video', 'archive', 'flash', or 'document' See File::$allowed_extensions for details of allowed extensions for each of these categories

Parameters

string $category

Category name

Return Value

$this

array getAllowedExtensions()

Returns list of extensions allowed by this field, or an empty array if there is no restriction

Return Value

array

Upload_Validator getValidator()

Get custom validator for this field

Return Value

Upload_Validator

$this setValidator(Upload_Validator $validator)

Set custom validator for this field

Parameters

Upload_Validator $validator

Return Value

$this

$this setFolderName(string $folderName)

Sets the upload folder name

Parameters

string $folderName

Return Value

$this

string getFolderName()

Gets the upload folder name

Return Value

string