|
|
|
|
@ -0,0 +1,33 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 未启用 PHP fileinfo 扩展时,原生 mime_content_type() 不存在,PhpSpreadsheet 等库会报错。
|
|
|
|
|
* 仅在缺失时提供极简实现(按扩展名推断),生产环境仍建议启用 extension=fileinfo。
|
|
|
|
|
*/
|
|
|
|
|
if (! function_exists('mime_content_type')) {
|
|
|
|
|
function mime_content_type(string $filename): string|false
|
|
|
|
|
{
|
|
|
|
|
if ($filename === '' || ! is_readable($filename)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
|
|
|
|
|
|
|
|
|
$map = [
|
|
|
|
|
'png' => 'image/png',
|
|
|
|
|
'jpg' => 'image/jpeg',
|
|
|
|
|
'jpeg' => 'image/jpeg',
|
|
|
|
|
'gif' => 'image/gif',
|
|
|
|
|
'webp' => 'image/webp',
|
|
|
|
|
'bmp' => 'image/bmp',
|
|
|
|
|
'tif' => 'image/tiff',
|
|
|
|
|
'tiff' => 'image/tiff',
|
|
|
|
|
'svg' => 'image/svg+xml',
|
|
|
|
|
'emf' => 'application/octet-stream',
|
|
|
|
|
'wmf' => 'application/x-msmetafile',
|
|
|
|
|
'bin' => 'application/octet-stream',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $map[$ext] ?? 'application/octet-stream';
|
|
|
|
|
}
|
|
|
|
|
}
|