Skip to content
Viames Marino edited this page Feb 26, 2026 · 2 revisions

Pair framework: File

Pair\Html\FormControls\File renders file upload inputs and provides MIME-category helpers.

Methods

  • accept(string|array $mimeType): self
  • acceptCategory(string $mimeCategory): self
  • acceptCategories(array $mimeCategories): self
  • capture(?string $cameraFacingMode = null): self
  • mimeCategory(string $mimeType): ?string (static)
  • render(): string

MIME categories

Built-in categories in File::MIME_TYPES:

  • audio
  • binary
  • csv
  • document
  • image
  • pdf
  • presentation
  • spreadsheet
  • video
  • zip

Behavior

  • accept(...) is cumulative: multiple calls append entries separated by commas.
  • acceptCategory(...) silently ignores unknown categories.
  • capture(...) sets the capture attribute for mobile camera/source hints.
  • mimeCategory(...) returns the first matching category for a MIME string or extension, otherwise null.

Examples

Allow images and PDFs:

$attachment = (new \Pair\Html\FormControls\File('attachment'))
    ->acceptCategory('image')
    ->acceptCategory('pdf')
    ->required();

Explicit MIME list + camera hint:

$avatar = (new \Pair\Html\FormControls\File('avatar'))
    ->accept(['image/png', 'image/jpeg'])
    ->capture('user');

Resolve category from MIME string:

$category = \Pair\Html\FormControls\File::mimeCategory('application/pdf');
// 'pdf'

Notes

The accept attribute helps UX but does not replace server-side upload validation.

See also: FormControl, Upload, Image.

Clone this wiki locally