问题
Laravel 7 on PHP 7 is detecting incorrect MIME type of application/octet-stream
for .ogg extension.
Here is the applicable file request dump:
Illuminate\Http\UploadedFile {#1274 ▼
-test: false
-originalName: "03 - See You Tonite.ogg"
-mimeType: "application/octet-stream"
Anybody know of a workaround for this?
回答1:
Check your mime type file first:
return $request->file('field_name')->getMimeType();
Now you can add the following code in the boot method in AppServiceProvider:
public function boot()
{
Validator::extend('ogg_extension', function($attribute, $value, $parameters, $validator) {
if(!empty($value->getClientOriginalExtension()) && ($value->getClientOriginalExtension() == 'ogg')){
return true;
}else{
return false;
}
});
}
来源:https://stackoverflow.com/questions/63538962/laravel-7-incorrect-mime-type-detected