| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\librarys\storage\drivers;
- use app\librarys\storage\exceptions\StorageException;
- use Qiniu\Auth;
- use Qiniu\Storage\UploadManager;
- class Qiniu extends BaseDriver
- {
- public $region = '';
- /**
- * Qiniu auth class
- *
- * @var Auth
- */
- protected $qiniuAuth;
- /**
- * Qiniu upload manager class
- *
- * @var UploadManager
- */
- protected $qiniuUploadManager;
- public function __construct($config = [])
- {
- parent::__construct($config);
- $this->qiniuAuth = new Auth($this->accessKey, $this->secretKey);
- // $zone = \Qiniu\Zone::zonez0(); //华东
- $arr = array('upload.qiniup.com', 'upload-z1.qiniup.com', 'upload-z2.qiniup.com', 'upload-as0.qiniup.com', 'upload-na0.qiniup.com');
- $url = $arr[(int)$this->zone];
- $zone = new \Qiniu\Zone([$url]);
- $config1 = new \Qiniu\Config($zone);
- $this->qiniuUploadManager = new UploadManager($config1);
- }
- public function put($localFile, $saveTo)
- {
- $token = $this->qiniuAuth->uploadToken($this->bucket);
- list($res, $err) = $this->qiniuUploadManager->putFile($token, $saveTo, $localFile);
- if ($err !== null) {
- throw new StorageException($err->message());
- }
- $ress = $this->region . '/' . $res['key'];
- return $ress;
- }
- }
|