【问题标题】:Laravel mimes validation rule not working for some file extensionsLaravel mimes 验证规则不适用于某些文件扩展名
【发布时间】:2017-03-15 05:05:51
【问题描述】:

我正在尝试使用mimes 验证规则来验证上传文件。

'attachment' => 'required|file|max:1024|mimes:png,gif,jpg,txt,pdf,doc,docx,zip,rar'  

它适用于某些扩展名为 php 的文件,但不适用于 js apk ovpn .... 等扩展名

有什么想法吗?

【问题讨论】:

  • 您尝试上传的文件是否具有准确代表其内容的扩展名?
  • @alaric 是的,我可以上传.js 文件(已测试)

标签: laravel laravel-validation


【解决方案1】:

您的消息错误看起来像您验证之前的样子。它们应该是这样的

$messages = [
            "attachment.required" => "error required",
            "attachment.mimes" => "error mines",
        ];

        $validator = Validator::make($data, [
            'attachment' => 'required|mimes:csv,txt',
        ], $messages);

        if ($validator->fails()) {
            return redirect('/home')
                ->withErrors($validator)
                ->withInput();
        } else {
          // your code here
        }

你能详细说明一下你的文件吗

【讨论】:

    猜你喜欢
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 2015-10-20
    • 2020-03-25
    相关资源
    最近更新 更多