gpt4 book ai didi

php - Laravel 5.5 验证多文件上传

转载 作者:行者123 更新时间:2023-12-01 10:24:39 25 4
gpt4 key购买 nike

如何在 Laravel 上仅使用一个验证来验证多个文件上传?

$this->validate($request, [
'project' => 'required|exists:project_details,id',
'location' => 'exists:project_details,location',
'plant_id' => 'exists:project_details,plant_id',
'capacity' => 'required|max:20',
'brief_description' => 'nullable|max:300',
'incident_details' => 'required|max:300',
'other_comments' => 'nullable|max:300',
'attachments.*' => 'required|file|mimes:xlsx,xls,csv,jpg,jpeg,png,bmp,doc,docx,pdf,tif,tiff'
]);

我正在尝试验证附件。
这是我的表格:
<input type="file" name="attachments[]" multiple>

最佳答案

您可以按照以下方式验证您的文件。

$input_data = $request->all();

$validator = Validator::make(
$input_data, [
'image_file.*' => 'required|file|mimes:xlsx,xls,csv,jpg,jpeg,png,bmp,doc,docx,pdf,tif,tiff'
],[
'image_file.*.required' => 'Please upload an image',
'image_file.*.mimes' => 'Only xlsx,xls,csv,jpg,jpeg,png,bmp,doc,docx,pdf,tif,tiff images are allowed',

]
);

if ($validator->fails()) {
$messages = $validator->messages();
return Redirect::to('/')->with('message', 'Your erorr message');
}

关于php - Laravel 5.5 验证多文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48636473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com