Laravel 7检测到不正确的MIME类型 [英] Laravel 7 Incorrect MIME Type Detected

查看:96
本文介绍了Laravel 7检测到不正确的MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 7上的Laravel 7正在检测到.ogg扩展名不正确的MIME类型的 application/octet-stream .

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"

有人知道解决方法吗?

推荐答案

请首先检查您的mime类型文件:

Check your mime type file first:

 return $request->file('field_name')->getMimeType();

现在,您可以在AppServiceProvider的启动方法中添加以下代码:

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;
            }
             
        });
    }

这篇关于Laravel 7检测到不正确的MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆