TP5 上传图片提示 非法图像文件

今天在写封面上传的时候碰到了,开始以为是layui的问题,看了下官方文档,做了个小demo测试没问题。

于是查看了tp的源码,在/thinkphp/library/think/File.php中 有一个图片严格检查。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* 检查图像文件 */
if (!$this->checkImg()) {
$this->error = 'illegal image files';
return false;
}

//其中checkImg的源码为
/**
* 检测图像文件
* @return bool
*/
public function checkImg()
{
$extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION));

/* 对图像文件进行严格检测 */
if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array($this->getImageType($this->filename), [1, 2, 3, 4, 6, 13])) {
return false;
}
return true;
}

想了想可能是没装exif之类的拓展,于是在装了exif,fileinfo的php拓展之后 一切正常


评论区