File and image
Purpose: adding files and images. The database stores only file paths from the project root, without the initial slash, and the files themselves are distributed across model folders in the userfiles/models/ directory.
Field type in the SQL table: char and varchar
Additional parameters:
max_size
Purpose: maximum allowed file size
Possible values: integer value in bytes
Default: allowed extensions are taken from the configuration file config/settings.php
allowed_extensions
Purpose: allowed file extensions
Possible values: array of extensions like ['doc', 'docx', 'pdf']
Default: allowed extensions are taken from the configuration file config/settings.php
allowed_mime_types
Purpose: allowed mime file types
Possible values: array of the form ['image/jpeg', 'image/webp', 'image/png']
Default: allowed extensions are taken from the configuration file config/settings.php (only for the image type)
max_width
Purpose: maximum allowed image width
Possible values: integer value in pixels
Default: allowed extensions are taken from the configuration file config/settings.php
max_height
Purpose: maximum allowed height images
Possible values: integer value in pixels
Default: allowed extensions are taken from the configuration file config/settings.php
form_preview_width
Purpose: maximum allowed width of a thumbnail copy of an image (for forms)
Possible values: integer value in pixels
Default: 150
form_preview_height
Purpose: maximum allowed height of a thumbnail copy of an image (for forms)
Possible values: integer value in pixels
Default: 150
multiple
Purpose: ability to upload multiple files at a time (file type for forms)
Possible values: integer value, maximum number of files
Default: null
Examples:
['Product image', 'image', 'image', ['required' => true, 'max_size' => 500000]]
['Download file', 'file', 'download_file', ['help_text' => 'Company product descriptions']]
['Resume', 'file', 'resume', ['allowed_extensions' => ['txt', 'doc', 'docx']]
['Attach files', 'file', 'files', ['files_folder' => 'files_upload', 'multiple' => 5]]
Previous section
Date and time