mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-09-10 14:29:46 +08:00
修改图片安全处理
This commit is contained in:
parent
b8c2c00b85
commit
8bf2ad4cbc
@ -57,10 +57,10 @@ 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'])) {
|
if (empty($ext) || !in_array(strtolower($ext), ['png', 'jpg', 'jpeg'])) {
|
||||||
$this->error('图片格式异常!');
|
$this->error('图片格式异常!');
|
||||||
}
|
}
|
||||||
$info = Storage::instance()->set(Storage::name($img, $ext ?: 'png', 'image/'), base64_decode($img));
|
$info = Storage::instance()->set(Storage::name($img, $ext, 'image/'), base64_decode($img));
|
||||||
$this->success('图片上传成功!', ['url' => $info['url']]);
|
$this->success('图片上传成功!', ['url' => $info['url']]);
|
||||||
} else {
|
} else {
|
||||||
$this->error('解析内容失败!');
|
$this->error('解析内容失败!');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user