form_file_select()
function form_file_select(string $name, array $attributes = []): string
Description
Generates an HTML file input element. Requires forms to use form_open_upload() for proper file upload handling.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $name | string | The name attribute for the file input. |
| $attributes | array | (optional) HTML attributes for the file input. Defaults to an empty array ([]). |
Return Value
| Type | Description |
|---|---|
| string | An HTML file input element. |
Example #1: Basic File Input
Example #2: File Input with Restrictions
Complete Upload Example
Notes
- Always use
form_open_upload()instead ofform_open()for forms containing file inputs. - Use
multipleattribute to allow multiple file selections. - Use
acceptattribute to restrict file types (e.g.,'.jpg,.png'or'image/*'). - For multiple files, append
[]to the field name:'images[]'. - Access uploaded files via
$_FILES['field_name']in your controller. - Configure PHP's
upload_max_filesizeandpost_max_sizefor larger files.