增加接口图片安全处理

This commit is contained in:
Anyon 2021-12-31 12:26:20 +08:00
parent 8e287d6473
commit b8c2c00b85

View File

@ -57,6 +57,9 @@ class Center extends Auth
$data = $this->_vali(['base64.require' => '图片内容不为空!']);
if (preg_match('|^data:image/(.*?);base64,|i', $data['base64'])) {
[$ext, $img] = explode('|||', preg_replace('|^data:image/(.*?);base64,|i', '$1|||', $data['base64']));
if (!in_array(strtolower($ext), ['png', 'jpg', 'jpeg'])) {
$this->error('图片格式异常!');
}
$info = Storage::instance()->set(Storage::name($img, $ext ?: 'png', 'image/'), base64_decode($img));
$this->success('图片上传成功!', ['url' => $info['url']]);
} else {