确保您的表单具有属性 enctype="multipart/form-data"
此外,如果您使用 mimes 验证,格式必须为 'mimes:jpeg,bmp,png' https://laravel.com/docs/5.6/validation#rule-mimes
您可以在此处阅读有关 enctype 属性的信息:enctype='multipart/form-data' 是什么意思?
在表格中尝试输入
files="true"
。
required|mimes:doc,docx,pdf
https://laravel.com/docs/5.4/validation#rule-mimes
编辑:当您使用
mimes:application/doc
时,实际上是mimetypes:application/doc
您好,我遇到了类似的问题,点击以下命令后一切都正确,问题得到解决
php artisan cache:clear , php artisan config:clear , php artisan route:clear
如果您遇到 .docx 扩展文件的任何问题,请使用如下验证
'cv' => 'mimetypes:application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/octet-stream,application/pdf'
这将有助于验证 doc、Docx 和 pdf 文件。
要显示正确的错误消息,请使用以下代码:
public function messages ()
{
return [
'cv.mimetypes' => 'The cv file must be a file of type: pdf, doc, docx.'
];
}
参考:Laravel 7
如果有人遇到同样的问题,您必须使用文件扩展名,而不是像这样的 mime 类型:
'file' => 'required|file|mimes:pdf,doc,docx'
可以找到扩展的完整列表:https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
如果有人正在寻找哑剧图像,请按以下方法操作。
'image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',