多文件请求验证不起作用
Multiple file request validation not working
我正在尝试通过请求验证上传多个文件,但验证规则应用不正确。我只想验证图像。我还设置了 mime 类型,但它不起作用。好像是什么问题?
我已经尝试放置 'fieldname.*' 并设置哑剧,但它没有按预期工作,它甚至阻止了图像。
这是我的输入字段:
<input type="file" name="files[]" multiple>
我的验证规则:
public function rules()
{
return [
'content' => 'nullable|string|max:3000',
'files.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
];
}
更改您的规则功能如下:
public function rules()
{
return [
'content' => 'nullable|string|max:3000',
'files' => 'array|mimes:jpeg,png,jpg,gif,svg|max:2048'
];
}
此外,请确保您的表单也具有 enctype="multipart/form-data"
属性。
感谢您的回答。你所有的答案都是正确的。我确实重启了我的服务器,它解决了这个问题。
我正在尝试通过请求验证上传多个文件,但验证规则应用不正确。我只想验证图像。我还设置了 mime 类型,但它不起作用。好像是什么问题?
我已经尝试放置 'fieldname.*' 并设置哑剧,但它没有按预期工作,它甚至阻止了图像。
这是我的输入字段:
<input type="file" name="files[]" multiple>
我的验证规则:
public function rules()
{
return [
'content' => 'nullable|string|max:3000',
'files.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
];
}
更改您的规则功能如下:
public function rules()
{
return [
'content' => 'nullable|string|max:3000',
'files' => 'array|mimes:jpeg,png,jpg,gif,svg|max:2048'
];
}
此外,请确保您的表单也具有 enctype="multipart/form-data"
属性。
感谢您的回答。你所有的答案都是正确的。我确实重启了我的服务器,它解决了这个问题。