MediaType uses ConstantsTrait
Enumeration of commonly used IANA media types (MIME types).
These are the values carried by the Content-Type and Accept HTTP
headers (RFC 9110 §8.3 / §12.5.1). Only the type/subtype is stored — use
self::withCharset() to append a charset parameter.
Only widely used types are listed; the full registry is far larger.
Example:
$response = $response->withHeader( HttpHeader::CONTENT_TYPE , MediaType::JSON ) ;
// or with a charset:
$response->withHeader( HttpHeader::CONTENT_TYPE , MediaType::withCharset( MediaType::HTML ) ) ;
Tags
Table of Contents
Constants
- AVIF : string = 'image/avif'
- `image/avif` — AV1 Image File Format.
- CSS : string = 'text/css'
- `text/css` — Cascading Style Sheets.
- CSV : string = 'text/csv'
- `text/csv` — Comma-separated values (RFC 4180).
- EVENT_STREAM : string = 'text/event-stream'
- `text/event-stream` — Server-Sent Events stream.
- FORM_URLENCODED : string = 'application/x-www-form-urlencoded'
- `application/x-www-form-urlencoded` — URL-encoded form body (RFC 1866).
- GIF : string = 'image/gif'
- `image/gif` — GIF image.
- GZIP : string = 'application/gzip'
- `application/gzip` — gzip-compressed payload (RFC 6713).
- HTML : string = 'text/html'
- `text/html` — HTML document.
- ICO : string = 'image/x-icon'
- `image/x-icon` — Windows icon (favicon).
- JAVASCRIPT : string = 'text/javascript'
- `text/javascript` — JavaScript source (RFC 9239).
- JOSE : string = 'application/jose'
- `application/jose` — JOSE object in compact serialization (RFC 7515).
- JOSE_JSON : string = 'application/jose+json'
- `application/jose+json` — JOSE object in JSON serialization (RFC 7515).
- JPEG : string = 'image/jpeg'
- `image/jpeg` — JPEG image.
- JSON : string = 'application/json'
- `application/json` — JSON payload (RFC 8259).
- JSON_LD : string = 'application/ld+json'
- `application/ld+json` — JSON-LD linked data.
- JSON_PATCH : string = 'application/json-patch+json'
- `application/json-patch+json` — JSON Patch document (RFC 6902).
- JWT : string = 'application/jwt'
- `application/jwt` — JSON Web Token (RFC 7519).
- MARKDOWN : string = 'text/markdown'
- `text/markdown` — Markdown text (RFC 7763).
- MERGE_PATCH_JSON : string = 'application/merge-patch+json'
- `application/merge-patch+json` — JSON Merge Patch document (RFC 7386).
- MULTIPART_ALTERNATIVE : string = 'multipart/alternative'
- `multipart/alternative` — Same content in alternative formats (RFC 2046).
- MULTIPART_BYTERANGES : string = 'multipart/byteranges'
- `multipart/byteranges` — Multiple range parts of a single document (RFC 9110).
- MULTIPART_FORM_DATA : string = 'multipart/form-data'
- `multipart/form-data` — Form submission with file parts (RFC 7578).
- MULTIPART_MIXED : string = 'multipart/mixed'
- `multipart/mixed` — Independent body parts (RFC 2046).
- MULTIPART_RELATED : string = 'multipart/related'
- `multipart/related` — Compound object of related parts (RFC 2387).
- NDJSON : string = 'application/x-ndjson'
- `application/x-ndjson` — Newline-delimited JSON stream.
- OCTET_STREAM : string = 'application/octet-stream'
- `application/octet-stream` — Arbitrary binary data (RFC 2046).
- PDF : string = 'application/pdf'
- `application/pdf` — Portable Document Format (RFC 8118).
- PNG : string = 'image/png'
- `image/png` — PNG image.
- PROBLEM_JSON : string = 'application/problem+json'
- `application/problem+json` — Problem Details for HTTP APIs (RFC 9457).
- SVG : string = 'image/svg+xml'
- `image/svg+xml` — Scalable Vector Graphics.
- TEXT : string = 'text/plain'
- `text/plain` — Plain text (RFC 2046).
- TEXT_XML : string = 'text/xml'
- `text/xml` — XML as text (RFC 7303).
- WASM : string = 'application/wasm'
- `application/wasm` — WebAssembly binary module.
- WEBP : string = 'image/webp'
- `image/webp` — WebP image.
- XML : string = 'application/xml'
- `application/xml` — XML payload (RFC 7303).
- ZIP : string = 'application/zip'
- `application/zip` — ZIP archive.
Methods
- withCharset() : string
- Appends a `charset` parameter to a media type, ready for a `Content-Type` header value.
Constants
AVIF
`image/avif` — AV1 Image File Format.
public
string
AVIF
= 'image/avif'
CSS
`text/css` — Cascading Style Sheets.
public
string
CSS
= 'text/css'
CSV
`text/csv` — Comma-separated values (RFC 4180).
public
string
CSV
= 'text/csv'
EVENT_STREAM
`text/event-stream` — Server-Sent Events stream.
public
string
EVENT_STREAM
= 'text/event-stream'
FORM_URLENCODED
`application/x-www-form-urlencoded` — URL-encoded form body (RFC 1866).
public
string
FORM_URLENCODED
= 'application/x-www-form-urlencoded'
GIF
`image/gif` — GIF image.
public
string
GIF
= 'image/gif'
GZIP
`application/gzip` — gzip-compressed payload (RFC 6713).
public
string
GZIP
= 'application/gzip'
HTML
`text/html` — HTML document.
public
string
HTML
= 'text/html'
ICO
`image/x-icon` — Windows icon (favicon).
public
string
ICO
= 'image/x-icon'
JAVASCRIPT
`text/javascript` — JavaScript source (RFC 9239).
public
string
JAVASCRIPT
= 'text/javascript'
JOSE
`application/jose` — JOSE object in compact serialization (RFC 7515).
public
string
JOSE
= 'application/jose'
JOSE_JSON
`application/jose+json` — JOSE object in JSON serialization (RFC 7515).
public
string
JOSE_JSON
= 'application/jose+json'
JPEG
`image/jpeg` — JPEG image.
public
string
JPEG
= 'image/jpeg'
JSON
`application/json` — JSON payload (RFC 8259).
public
string
JSON
= 'application/json'
JSON_LD
`application/ld+json` — JSON-LD linked data.
public
string
JSON_LD
= 'application/ld+json'
JSON_PATCH
`application/json-patch+json` — JSON Patch document (RFC 6902).
public
string
JSON_PATCH
= 'application/json-patch+json'
JWT
`application/jwt` — JSON Web Token (RFC 7519).
public
string
JWT
= 'application/jwt'
MARKDOWN
`text/markdown` — Markdown text (RFC 7763).
public
string
MARKDOWN
= 'text/markdown'
MERGE_PATCH_JSON
`application/merge-patch+json` — JSON Merge Patch document (RFC 7386).
public
string
MERGE_PATCH_JSON
= 'application/merge-patch+json'
MULTIPART_ALTERNATIVE
`multipart/alternative` — Same content in alternative formats (RFC 2046).
public
string
MULTIPART_ALTERNATIVE
= 'multipart/alternative'
MULTIPART_BYTERANGES
`multipart/byteranges` — Multiple range parts of a single document (RFC 9110).
public
string
MULTIPART_BYTERANGES
= 'multipart/byteranges'
MULTIPART_FORM_DATA
`multipart/form-data` — Form submission with file parts (RFC 7578).
public
string
MULTIPART_FORM_DATA
= 'multipart/form-data'
MULTIPART_MIXED
`multipart/mixed` — Independent body parts (RFC 2046).
public
string
MULTIPART_MIXED
= 'multipart/mixed'
MULTIPART_RELATED
`multipart/related` — Compound object of related parts (RFC 2387).
public
string
MULTIPART_RELATED
= 'multipart/related'
NDJSON
`application/x-ndjson` — Newline-delimited JSON stream.
public
string
NDJSON
= 'application/x-ndjson'
OCTET_STREAM
`application/octet-stream` — Arbitrary binary data (RFC 2046).
public
string
OCTET_STREAM
= 'application/octet-stream'
`application/pdf` — Portable Document Format (RFC 8118).
public
string
PDF
= 'application/pdf'
PNG
`image/png` — PNG image.
public
string
PNG
= 'image/png'
PROBLEM_JSON
`application/problem+json` — Problem Details for HTTP APIs (RFC 9457).
public
string
PROBLEM_JSON
= 'application/problem+json'
SVG
`image/svg+xml` — Scalable Vector Graphics.
public
string
SVG
= 'image/svg+xml'
TEXT
`text/plain` — Plain text (RFC 2046).
public
string
TEXT
= 'text/plain'
TEXT_XML
`text/xml` — XML as text (RFC 7303).
public
string
TEXT_XML
= 'text/xml'
WASM
`application/wasm` — WebAssembly binary module.
public
string
WASM
= 'application/wasm'
WEBP
`image/webp` — WebP image.
public
string
WEBP
= 'image/webp'
XML
`application/xml` — XML payload (RFC 7303).
public
string
XML
= 'application/xml'
ZIP
`application/zip` — ZIP archive.
public
string
ZIP
= 'application/zip'
Methods
withCharset()
Appends a `charset` parameter to a media type, ready for a `Content-Type` header value.
public
static withCharset(string $type[, string $charset = Charset::UTF_8 ]) : string
Example:
MediaType::withCharset( MediaType::JSON ); // 'application/json; charset=utf-8'
MediaType::withCharset( MediaType::HTML , 'iso-8859-1' );
Parameters
- $type : string
-
One of the class constants (or any media type).
- $charset : string = Charset::UTF_8
-
The charset token. One of Charset; defaults to Charset::UTF_8.
Return values
string —The media type with a ; charset=<charset> parameter.