0

这是我的请求代码..

public function rules()
{
    return [
      'file' => 'nullable|array|min:1',
      'file.*' => 'nullable|file|mimes:xlsx|max:50000', 
    ];
}

这是html代码

<form class='curd-form' id='form' @submit.prevent='curd_create("{{$model[0]}}")' method='post' action='{{$path}}{{$model[0]}}' enctype="multipart/form-data">
    <input id='file' class='btn btn-success' type='file' {{$file_requires ?? null}} accept='{{$file_types ?? null}}'  multiple  name='file[]' />
    <input type='submit' />                 
</form>

现在,如果我删除验证一切正常.. 但如果我尝试上传 excel 文件,我得到了这个错误......

在此处输入图像描述

这是excel文件

New Microsoft Excel Worksheet.xlsx

现在这发生在我添加到规则验证中的任何类型的文件中,如果我添加的话

'file.*' => 'nullable|file|mimes:xlsx,jpg,png,pdf|max:50000', 

我在同一个扩展名中遇到了同样的错误..这是提交表单的 axios 代码

this.show_curd_errors = false;
this.errors = [];
var frm = $('.curd-form');
let formData = new FormData(frm[0]);
var add_or_print = $("#add_or_print").val();
axios.post(path+page_title,formData)
.then((response) => 
{
    console.log(response)
}).catch (error => {
    console.log(error);
    var error = error.response['data']['errors'];
    this.errors = error;
    hide_loading();
});

我的代码有什么错误..谢谢..

4

1 回答 1

0

你有这样声明 Mime 类型:

https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

这将起作用:

   'file.*' => 'required|file|max:600|mimetypes:application/vnd.ms-excel',

mime规则,控制文件扩展名。

您的 Excel 文件可能是 .xlsx 或 .xls

mimetypes不关心文件扩展名。

于 2020-11-20T15:04:11.787 回答