第二步:把里面\cos-php-sdk-v5-master\cos\src 下的三个目录复制到项目的extend目录下
第三步:在要使用的地方 use Qcloud\Cos\Client;
附一个代码:
/**
* 上传图片到腾讯云图片服务器
*/
public function upfile () {
$cosClient = new Client(config("tengxunyun"));
$file = request()->file('file');
if ($file) {
try {
$result = $cosClient->putObject(
[
'Bucket' => "pics",
'Key' => date("Y-m-d") . "/" . md5(microtime()) . '.jpg',
'Body' => fopen($file->getInfo()['tmp_name'], 'rb'),
"ACL" => "public-read-write",
"ContentType" => "image/jpeg"
]
);
return json(
[
"code" => 0,
"msg" => '上传成功',
"data" => [
"src" => str_replace("cos.ap-beijing", "picbj", $result['ObjectURL']),
"title" => ""
]
]
);
} catch (\Exception $e) {
return json(
[
"code" => 1,
"msg" => $e,
"data" => [
"src" => "",
"title" => ""
]
]
);
}
}
} 最佳答案