<?php use OSS\OssClient; USE OSS\Core\OssException; require_once (dirname ( __FILE__ ) . '/../../extralib/autoload.php'); Class AliUploadHandler{ var $Access_Key ; var $Secret_Key ; var $bucket ; var $endpoint ; public function __construct(){ $this->init(); } public function init(){ $this->Access_Key = OSS_ACCESS_KEY; $this->Secret_Key = OSS_ACCESS_SECRET; $this->bucket = OSS_BUCKET; $this->endpoint = OSS_END_POINT; } /** * 上传接口 * @Author * @DateTime 2017-03-08 * @param string $bucket bucket name * @param string $object object name * @param string $file local file path * @param array $options * @throws OssException [文件类型] */ public function uploadImg($dst,$src){ //获取对象 $auth = new OssClient($this->Access_Key,$this->Secret_Key,$this->endpoint); try { //上传图片 $result = $auth->uploadFile($this->bucket,$dst,$src); return $result['info']['url']; } catch (OssException $e) { ErrorLogger::doOutput(__FUNCTION__ . "uploadImg: FAILED\n"); ErrorLogger::doOutput($e->getMessage() . "\n"); return $e->getMessage(); } ErrorLogger::doOutput(__FUNCTION__ . "uploadImg: OK" . "\n"); } /** * @Author * @DateTime 2018-03-08 * @return [type] [description] */ public function uploadVideo($dst,$src){ $ossClient = new OssClient($this->Access_Key,$this->Secret_Key,$this->endpoint); try{ $result = $ossClient->multiuploadFile($this->bucket,$dst,$src); return $result['info']['url']; } catch(OssException $e) { ErrorLogger::doOutput(__FUNCTION__ . "uploadVideo: FAILED\n"); ErrorLogger::doOutput($e->getMessage() . "\n"); return; } ErrorLogger::doOutput(__FUNCTION__ . "uploadVideo: OK" . "\n"); } /** * 删除文件 * * @param $srcFile 文件路径 * */ public function delete($desPath) { $ossClient = new OssClient($this->Access_Key,$this->Secret_Key,$this->endpoint); try{ $ossClient->deleteObject($this->bucket, $desPath); } catch(OssException $e) { ErrorLogger::doOutput(__FUNCTION__ . "delete: FAILED\n"); ErrorLogger::doOutput($e->getMessage() . "\n"); return; } ErrorLogger::doOutput(__FUNCTION__ . "delete: OK" . "\n"); } }