0

我正在尝试在使用 dropzone/vue 库的 laravel 和 vue.js 中上传文件并验证文件,该文件具有各种 mimetype,例如 doc、docx、xls、xlsx、ppt、jpg、jpeg、ptx、gif、png, txt,这是我的 laravel 代码片段。代码看起来不错,但我仍然无法验证 jpg 和 jpeg mime 类型。我想知道如何将错误传递给 vue 组件

public function postFileUpload(Request $request)
    {
        $validator = Validator::make($request->all(),
            ['file' => 'required|mimes:png,gif,pdf,jpg,jpeg,txt|max:8192']
        );
        if ($validator->fails()) {
            echo 'in';
            exit();
//            return redirect()->back()->withErrors($validator->errors());
//            return redirect()->back()->withErrors($validator)->withInput()->withError('please select file type');
        } else {

            echo 'out';
            exit();
        }
    }
4

1 回答 1

1

考虑改用 vee-validate:http: //vee-validate.logaretm.com/validation.html#rule-ext在客户端验证文件

v-validate.reject="'required|ext:png,gif,pdf,jpg,jpeg,txt|size:8192'"

于 2018-04-12T08:53:36.113 回答