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

ParameterTypeDescription
$namestringThe name attribute for the file input.
$attributesarray(optional) HTML attributes for the file input. Defaults to an empty array ([]).

Return Value

TypeDescription
stringAn 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 of form_open() for forms containing file inputs.
  • Use multiple attribute to allow multiple file selections.
  • Use accept attribute 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_filesize and post_max_size for larger files.