getMimeType.php
Table of Contents
Functions
- getMimeType() : string|null
- Detects the MIME type of a file using the `finfo` extension.
Functions
getMimeType()
Detects the MIME type of a file using the `finfo` extension.
getMimeType(string $file) : string|null
This is the low-level primitive shared by the higher-level MIME helpers
(hasMimeType(), getImageMimeType(), tarFileInfo(),
zipFileInfo()). It returns the raw type reported by
finfo (e.g. text/plain, application/zip) without any normalization.
The function never throws: it returns null when the path is not a file or
when detection fails (including an empty result), so callers can decide how
to react (a boolean check, a fallback label such as 'unknown', etc.).
Parameters
- $file : string
-
Path to the file to inspect.
Tags
Return values
string|null —The detected MIME type, or null if $file is not a file or detection failed.