PHP's finfo
class wraps the fileinfo
functions which can be used to get the MIME type of a file:
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->file('/tmp/test-file.xlsx');
This will give us a $mimeType
of application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
and is a great way to dynamically get the MIME type of a file.
Here is the PHP documenation for the finfo
class: https://www.php.net/manual/en/class.finfo.php, and here are the constants that can be passed when instantiating the class: https://www.php.net/manual/en/fileinfo.constants.php