mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-05-22 06:49:15 +08:00
增加接口图片安全处理
This commit is contained in:
parent
8e287d6473
commit
b8c2c00b85
@ -57,6 +57,9 @@ class Center extends Auth
|
|||||||
$data = $this->_vali(['base64.require' => '图片内容不为空!']);
|
$data = $this->_vali(['base64.require' => '图片内容不为空!']);
|
||||||
if (preg_match('|^data:image/(.*?);base64,|i', $data['base64'])) {
|
if (preg_match('|^data:image/(.*?);base64,|i', $data['base64'])) {
|
||||||
[$ext, $img] = explode('|||', preg_replace('|^data:image/(.*?);base64,|i', '$1|||', $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));
|
$info = Storage::instance()->set(Storage::name($img, $ext ?: 'png', 'image/'), base64_decode($img));
|
||||||
$this->success('图片上传成功!', ['url' => $info['url']]);
|
$this->success('图片上传成功!', ['url' => $info['url']]);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user