Bucket = $config['Bucket']; $this->Region = $config['Region']; $this->APPID = $config['APPID']; $this->SecretId = $config['SecretId']; $this->SecretKey = $config['SecretKey']; } /** * 腾讯OS * @param string $localPath 本地路径 * @param string $name 文件名 * @return mixed * @throws CommonException * @author Administrator */ public function upload($localPath = '', $name = '') { $cosClient = new Client( [ 'region' => $this->Region, 'credentials' => [ 'secretId' => $this->SecretId, 'secretKey' => $this->SecretKey, ] ] ); try { $result = $cosClient->Upload( $this->Bucket, $name, fopen($localPath, 'rb') ); } catch (\Exception $e) { throw new CommonException(['msg' => $e->getMessage()]); } return $result; } public function uploadStream($stream, $name = '') { $cosClient = new Client( [ 'region' => $this->Region, 'credentials' => [ 'secretId' => $this->SecretId, 'secretKey' => $this->SecretKey, ] ] ); try { $result = $cosClient->Upload( $this->Bucket, $name, $stream ); } catch (\Exception $e) { throw new CommonException(['msg' => $e->getMessage()]); } return $result; } }