IN_REMOTEAK, "accessKeySecret" => IN_REMOTESK, "bucket" => IN_REMOTEBK, "domain" => IN_REMOTEDK]; public $bucket = ""; public $domain = ""; public $auth; public $bucketManager; public $token = ""; function __construct($config = []) { if (!empty($config)) { $this->config = $config; } $accessKeyId = $this->config['accessKeyId']; $accessKeySecret = $this->config['accessKeySecret']; $this->bucket = $this->config['bucket']; $this->domain = $this->config['domain']; $this->auth = new Auth($accessKeyId, $accessKeySecret); $this->token = $this->getToken(); $this->config = new Config(); } function getToken() { return $this->auth->uploadToken($this->bucket); } function download($Key) { return false; } function delete($Key) { if (!$this->file_exists($Key)) { return true; } $this->bucketManager = new BucketManager($this->auth, $this->config); list($fileInfo, $err) = $this->bucketManager->delete($this->bucket, $Key); if ($err) { return false; } else { return true; } } function file_exists($Key) { $this->bucketManager = new BucketManager($this->auth, $this->config); list($fileInfo, $err) = $this->bucketManager->stat($this->bucket, $Key); if ($err) { return false; } else { return array('src' => $Key, 'domain_src' => $this->domain . $Key); } } function upload($Key = '', $filePath = '') { if ($Key && $filePath) { } else { if (!$_FILES && !isset($_FILES['file'])) { return array('msg' => '无法识别的文件'); } $name = date('Ymd-His') . $_FILES['file']['name']; $Key = "uploads/test/" . $name; $filePath = $_FILES['file']['tmp_name']; } $uploadMgr = new UploadManager(); try { list($ret, $err) = $uploadMgr->putFile($this->token, $Key, $filePath); return array('src' => $Key, 'domain_src' => $this->domain . $Key); } catch (\Exception $exception) { return array('error' => $exception); } } function refresh($urls = [], $dirs = []) { $cdnManager = new CdnManager($this->auth); $res = array(); if ($urls) { list($refreshResult, $refreshErr) = $cdnManager->refreshUrls($urls); if ($refreshErr != null) { $res['urls'] = $refreshErr; } else { $res['urls'] = $refreshResult; } } if ($dirs) { list($refreshResult, $refreshErr) = $cdnManager->refreshDirs($dirs); if ($refreshErr != null) { $res['dirs'] = $refreshErr; } else { $res['dirs'] = $refreshResult; } } return $res; } }