增加接口二进制上传

This commit is contained in:
Anyon 2020-12-25 16:22:24 +08:00
parent fe15a7dd32
commit fa08383513

View File

@ -63,7 +63,7 @@ class Center extends Auth
} }
/** /**
* 上传Base64图片 * Base64 图片上传
*/ */
public function image() public function image()
{ {
@ -83,6 +83,29 @@ class Center extends Auth
} }
} }
/**
* 二进制文件上传
* @throws \think\admin\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function upload()
{
$file = $this->request->file('file');
if (empty($file)) $this->error('文件上传异常!');
$extension = strtolower($file->getOriginalExtension());
if (in_array($extension, ['php', 'sh'])) $this->error('禁止上传此类文件!');
$bina = file_get_contents($file->getRealPath());
$name = Storage::name($file->getPathname(), $extension, '', 'md5_file');
$info = Storage::instance()->set($name, $bina, false, $file->getOriginalName());
if (is_array($info) && isset($info['url'])) {
$this->success('文件上传成功!', $info);
} else {
$this->error('文件上传失败!');
}
}
/** /**
* 绑定用户邀请人 * 绑定用户邀请人
* @throws \think\Exception * @throws \think\Exception