Mime
in package
Class responsible for handling MIME types and file extensions.
Tags
Table of Contents
- check() : bool
- Check if the MIME type matches the accepted types.
- get() : string|array<string|int, mixed>|null
- Get the MIME type for a file extension.
- getAccept() : string
- Get the accept string for input of type "file".
- getMimeTypes() : array<string|int, mixed>
- Get an array of MIME types.
Methods
check()
Check if the MIME type matches the accepted types.
public
static check(array<string|int, mixed> $typies, string $mime) : bool
Used for validating uploaded files.
Parameters
- $typies : array<string|int, mixed>
-
The accepted file types.
- $mime : string
-
The MIME type to check, usually obtained from the uploaded file.
Tags
Return values
bool —True if the MIME type matches any of the accepted types, false otherwise.
get()
Get the MIME type for a file extension.
public
static get(string|array<string|int, mixed> $exts) : string|array<string|int, mixed>|null
Returns null if not found.
Parameters
- $exts : string|array<string|int, mixed>
-
The file extension(s).
Tags
Return values
string|array<string|int, mixed>|null —The MIME type(s) corresponding to the given extension(s).
getAccept()
Get the accept string for input of type "file".
public
static getAccept(array<string|int, mixed> $typies) : string
Returns a comma-separated string of MIME types.
Parameters
- $typies : array<string|int, mixed>
-
The file types.
Tags
Return values
string —The accept string for the given file types.
getMimeTypes()
Get an array of MIME types.
private
static getMimeTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of MIME types.