| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\librarys\storage\drivers;
- use app\librarys\storage\exceptions\StorageException;
- use Qcloud\Cos\Client as CosClient;
- class Qcloud extends BaseDriver
- {
- public $region;
- public $appId;
- /**
- * Tencent cloud COS Client
- *
- * @var CosClient
- */
- protected $cosClient;
- public function __construct($config = [])
- {
- parent::__construct($config);
- $this->cosClient = new CosClient(
- [
- 'region' => $this->region,
- 'credentials' => [
- 'appId' => $this->appId,
- 'secretId' => $this->accessKey,
- 'secretKey' => $this->secretKey,
- ],
- ]
- );
- }
- public function put($localFile, $saveTo)
- {
- $handle = fopen($localFile, 'rb');
- try {
- $saveTo = ltrim($saveTo, '/');
- $res = $this->cosClient->putObject(
- [
- 'Bucket' => $this->bucket,
- 'Key' => $saveTo,
- 'Body' => $handle,
- ]
- );
- } catch (\Exception $ex) {
- throw new StorageException($ex->getMessage());
- }
- return $res->offsetGet('Location');
- }
- }
|