-
Notifications
You must be signed in to change notification settings - Fork 2
File
Viames Marino edited this page Feb 26, 2026
·
2 revisions
Pair\Html\FormControls\File renders file upload inputs and provides MIME-category helpers.
accept(string|array $mimeType): selfacceptCategory(string $mimeCategory): selfacceptCategories(array $mimeCategories): selfcapture(?string $cameraFacingMode = null): self-
mimeCategory(string $mimeType): ?string(static) render(): string
Built-in categories in File::MIME_TYPES:
audiobinarycsvdocumentimagepdfpresentationspreadsheetvideozip
-
accept(...)is cumulative: multiple calls append entries separated by commas. -
acceptCategory(...)silently ignores unknown categories. -
capture(...)sets thecaptureattribute for mobile camera/source hints. -
mimeCategory(...)returns the first matching category for a MIME string or extension, otherwisenull.
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'The accept attribute helps UX but does not replace server-side upload validation.
See also: FormControl, Upload, Image.