File uploads

A has_one image or file gets an upload field. Files stay protected and are only delivered through the controller that shows the record.

The code

app/src/Controllers/ContactController.php – Photo in the field layout whole file
protected function defineFieldLayout(?DataObject $record): ?FieldLayout
{
return FieldLayout::create()
->group('Person', ['FirstName', 'Surname', 'PhotoID'], true, 'person')
->group('Contact', ['Email', 'Phone', 'Role', 'ClientID', 'IsPrimary'], true, 'contact');
}

protected function formFields(FieldList $fields): FieldList
{
// Photo is a has_one Image: the kit puts an upload field here.
$fields->dataFieldByName('PhotoID')
?->setAllowedExtensions(['jpg', 'jpeg', 'png', 'webp'])
->setMaxFileSize('2M');
return $fields;
}
app/_config/demo.yml – Limits of this public demo whole file
# Public demo: small images only, no other files.
Atwx\SilverstripeFrontdeskKit\Forms\FileUploadField:
max_file_size: '2M'
allowed_extensions: [jpg, jpeg, png, webp]