| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\librarys\storage\drivers;
- use app\librarys\storage\exceptions\StorageException;
- use OSS\Core\OssException;
- use OSS\OssClient;
- class Aliyun extends BaseDriver
- {
- public $isCName = false;
- public $endPoint = '';
- /**
- * Aliyun OSS Client
- *
- * @var OssClient
- */
- protected $ossClient;
- public function __construct($config = [])
- {
- parent::__construct($config);
- $this->ossClient = new OssClient(
- $this->accessKey,
- $this->secretKey,
- $this->endPoint,
- $this->isCName
- );
- }
- public function put($localFile, $saveTo)
- {
- try {
- $res = $this->ossClient->uploadFile($this->bucket, $saveTo, $localFile);
- } catch (OssException $ex) {
- throw new StorageException($ex->getErrorMessage() ?: $ex->getMessage());
- }
- return $res['oss-request-url'];
- }
- }
|