当前路径:vendor/veryinf/mb-helper/src/storage/Aliyun.php <?php namespace mb\helper\storage; use mb\helper\Storage; use OSS\Core\OssException; use OSS\OssClient; class Aliyun extends Storage { private $config = [ 'scheme' => 'http', 'key' => '', 'secret' => '', 'endpoint' => '', 'host' => '', 'bucket' => '', 'prefix' => '', ]; /** * @var null|OssClient */ private $client = null; /** * Aliyun constructor. * * @param $config */ public function __construct($config) { $this->config = $config; try { $this->client = new OssClient($this->config['key'], $this->config['secret'], $this->config['endpoint']); } catch (OssException $e) { throw error($e->getCode(), $e->getMessage()); } } public function domainUrl() { $urlPrefix = "{$this->config['scheme']}://{$this->config['host']}/{$this->config['prefix']}"; return $urlPrefix; } public function put($path, $file) { if (!is_file($file)) { return error(-10, '没有指定上传的文件'); } try { $fullPath = $this->config['prefix'] . $path; $this->client->uploadFile($this->config['bucket'], $path, $file); $return = [ 'filename' => $path, 'url' => $this->domainUrl() . $path ]; return $return; } catch (OssException $e) { return error($e->getCode(), $e->getMessage()); } } public function putContent($path, $content) { if (empty($content)) { return error(-10, '没有指定上传的内容'); } try { $fullPath = $this->config['prefix'] . $path; $this->client->putObject($this->config['bucket'], $fullPath, $content); $return = [ 'filename' => $path, 'url' => $this->domainUrl() . $path ]; return $return; } catch (OssException $e) { return error($e->getCode(), $e->getMessage()); } } /** * @param string $path * @param bool $isFull * @return |true */ public function delete($path, $isFull = false) { if ($isFull) { $path = substr($path, strlen($this->domainUrl())); } $fullPath = $this->config['prefix'] . $path; $this->client->deleteObject($this->config['bucket'], $fullPath); return true; } public function fetch($path, $url) { // TODO: Implement fetch() method. } public function download($path) { try { $fullPath = $this->config['prefix'] . $path; $data = $this->client->getObject($this->config['bucket'], $fullPath); return $data; } catch (OssException $e) { return error($e->getCode(), $e->getMessage()); } } }
相关源码
- 可旋转的彩色立方体C#源代码2021-10-29
- 在线考试系统2021-10-15
- EduSoho开源网校系统源码2019-06-27
- 仿拼多多小程序商城源码2019-06-06
- PHP5网站运行监测系统源码2017-04-14
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号