目前我正在开发一个用户可以将文件上传到我的系统的应用程序 . 我已经关注了laravel提供的文档中的所有内容,下面是我的代码 .
在我的HTML中,我的图像输入
<input type="file" name="thread_image">
在我的控制器中,我已完成如下验证
$validator = Validator::make($request::all(),
[
'thread_title' => 'required|max:100',
'thread_remark' => 'max:1000',
'thread_image' => 'required|mimes:jpeg,jpg,png',
],
[
'thread_title.required' => 'Please fill in thread title.',
'thread_title.max' => 'Thread title has exceeded 100 characters.',
'thread_remark.max' => 'Thread remark has exceeded 1000 characters.',
'thread_image.required' => 'Please select an image to post this thread.',
'thread_image.mimes' => 'Please select an correct image with the format of jpeg,jpg,png.',
]);
if ($validator->fails()) {
return Redirect::back()
->withErrors($validator)
->withInput();
}
其他输入已正确验证,确切图像 . 我做错了吗?我试着上传jpeg,jpg和png,他们都没有通过验证 .
1 回答
表单标记中是否有enctype =“multipart / form-data”属性
enctype属性指定在将表单数据提交到服务器时应如何编码表单数据 . 您需要这个来提交图像 .