首页> 实战笔录 >PHP开发笔记 >ThinkPHP ThinkPHP
TP6上传图片验证时报错think\\Validate::check() must be of the type array
作者:小萝卜 2020-09-14 【 TP6 】 浏览 2065
简介验证图片validate(['image'=>'filesize:10240|fileExt:jpg|image:200,200,jpg'])->check($files);时报错:{"code":0,"message":"Argument 1 passed to think\\Validate::check() must be of the type array, object given, called in D:\\Website\\aovd\\app\\admin\\controller\\Upload.php on line 31"}
按照官方文档做图片上次验证时报错!
官网代码:
报错提示:
{"code":0,"message":"Argument 1 passed to think\\Validate::check() must be of the type array, object given, called in D:\\Website\\aovd\\app\\admin\\controller\\Upload.php on line 31"}
问题解决:
{"state":200,"title":"上传成功","mess":"\/fielspath\/Images\/"}
官网代码:
validate(['image'=>'filesize:10240|fileExt:jpg|image:200,200,jpg'])->check($files);
报错提示:
{"code":0,"message":"Argument 1 passed to think\\Validate::check() must be of the type array, object given, called in D:\\Website\\aovd\\app\\admin\\controller\\Upload.php on line 31"}
解决办法:
将check里面的值改为数组
validate(['image'=>'filesize:10240|fileExt:jpg|image:200,200,jpg'])->check(['file'=>$file]);
也可以这么写
validate(['image'=>['filesize'=>10240,'fileExt'=>'jpg']])->check(['file'=>$file]);
问题解决:
{"state":200,"title":"上传成功","mess":"\/fielspath\/Images\/"}
很赞哦! (0)
下一篇:TP6权限管理 Auth库的使用
相关文章
- TP3.2使用join查询实例以及注意事项
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Attr_id' in 'where clause'
- TP5.0视图和模板
- TP6定义常量报错:Use of undefined constant CONTROLLER_NAME - assumed 'CONTROLLER_NAME'
- TP5 添加平铺水印并设置水印之间的间距
- PayPal支付ThinkPHP3.2源代码
- TP5.1 钩子与行为应用
- tp5动态创建mysql数据表
- TP6 TP5一键生成sitemap站点地图索引文件 代码分享
- tp5使用jwt生成token,做api的用户认证