-
Notifications
You must be signed in to change notification settings - Fork 2
FileMediaType
Viames Marino edited this page Apr 28, 2026
·
2 revisions
Pair\Http\FileMediaType is the shared MIME type and file-extension category registry used by upload handling and file input controls.
Returns all MIME types and extensions for a category.
Returns the first category matching a MIME type or file extension.
Returns every category matching a MIME type or file extension.
Returns whether a MIME type or extension belongs to a specific category. Use this for validation when a MIME type can belong to more than one category, such as text/plain.
audiobinarycsvdocumentflashimagepdfpresentationspreadsheetvideozip
use Pair\Http\FileMediaType;
$category = FileMediaType::category('application/pdf');
// 'pdf'
$acceptValues = FileMediaType::categoryTypes('image');
if (FileMediaType::matchesCategory('text/plain', 'csv')) {
// Accept CSV files detected by servers as text/plain.
}use Pair\Http\FileMediaType;
use Pair\Http\UploadedFile;
$upload = UploadedFile::fromGlobals('attachment');
$mediaType = $upload->mediaType();
if (!is_string($mediaType) || !FileMediaType::matchesCategory($mediaType, 'document')) {
throw new \RuntimeException('Attachment must be a document.');
}See also: UploadedFile, File.