master
lion 5 days ago
parent 9724a2750f
commit b7698c4d85

@ -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';
}
}

@ -26,7 +26,10 @@
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"files": [
"bootstrap/mime_content_type_polyfill.php"
]
},
"autoload-dev": {
"psr-4": {

Loading…
Cancel
Save