Laravel MIME 验证不适用于 .doc 文件

Laravel MIME validation not working with .doc file

验证表单与另一个扩展程序成功配合使用,但不适用于 .doc

<form method="POST" action="{{ route('documents.store') }}" class="needs-validation" novalidate enctype="multipart/form-data">
    @csrf

    <label for="document" class="form-label">
        File <strong class="text-azul">(Files accepteds: PDF,WORD,JPG,PNG)</strong>
    </label>
    <input class="form-control" type="file" id="document" name="document" accept=".doc,.docx,.pdf,.png,.jpg" required>
    <x-jet-button>{{ __('Save') }}</x-jet-button>
</form>

在控制器中:

$request->validate([
    'document' => 'file|mimes:doc,docx,pdf,png,jpg,jpeg',
]);

在扩展名为 .doc 的 select 文件上,它 returns:

The document must be a file of type: doc, docx, pdf, png, jpg, jpeg.

根据 Laravel documentation 您还可以验证 mime 类型:

$request->validate([
    'document' => 'mimetypes:application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
]);

上面的例子应该只允许 docdocx 类型(您可以根据需要添加任意数量)。

请在下面的link中查找常见的 mime 类型:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types