切换镜像文件
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
composer create-project topthink/think=5.1.* tp5
安装OSS PHP SDK
composer require aliyuncs/oss-sdk-php
private function new_oss()
{
//获取配置项,并赋值给对象$config
$config = config(‘aliyun_oss’);
//实例化OSS
KaTeX parse error: Undefined control sequence: \OSS at position 11: oss = new \̲O̲S̲S̲\OssClient(config[‘KeyId’], $config[‘KeySecret’], $config[‘Endpoint’]);
return KaTeX parse error: Expected 'EOF', got '}' at position 7: oss; }̲ private funct…path)
{
try {
$ossClient = $this->new_oss();
$bucket = ‘qimg1’;
$time = time();
$object = ‘newadmin/’ . date(‘Y/m/d’) . ‘/’ . $time . ‘.jpg’;
$res =
o
s
s
C
l
i
e
n
t
−
>
u
p
l
o
a
d
F
i
l
e
(
ossClient->uploadFile(
ossClient−>uploadFile(bucket, $object,
p
a
t
h
)
;
u
n
l
i
n
k
(
path); unlink(
path);unlink(path);
return $res;
} catch (OssException $e) {
return $e->getMessage();
}
}
在app.php里配置
‘aliyun_oss’ => [
‘KeyId’ => ‘’, // 阿里云oss key_id
‘KeySecret’ => ‘’, // 阿里云oss key_secret
‘Endpoint’ => ‘’, // 阿里云oss endpoint
‘BUCKET’ => ‘’ // bucken 名称
],