Laravel 验证 pdf mime
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35694905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel validation pdf mime
提问by amin
I have tried below mime types for validating PDF files.but none of them doesnt pass the validation .
我已经尝试过以下 mime 类型来验证 PDF 文件。但它们都没有通过验证。
$rules = [
....
"file" => "required|mimes:application/pdf, application/x-pdf,application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf|max:10000"
....
]
回答by Froxz
Just add file extension
只需添加文件扩展名
$rules = [
"file" => "required|mimes:pdf|max:10000"
]
From laravel Docs:
来自 Laravel 文档:
Even though you only need to specify the extensions, this rule actually validates against the MIME type of the file by reading the file's contents and guessing its MIME type.
Update:
更新:
Starting from Laravel 5.2, you could validate file upload against full MIME type, new validationrule called: mimetypes
.
从开始Laravel 5.2,你可以验证对全MIME类型,文件上传新的验证规则叫做:mimetypes
。
$rules = [
"file" => "required|mimetypes:application/pdf|max:10000"
]