config = get_system_config(); $endpoint = $this->config['oss_region_url']; $this->bucket= $this->config['oss_bucket_name']; //获取配置 $this->ossClient = new OssClient( $this->config['oss_access_key_id'], $this->config['oss_access_key_secret'], $endpoint ); } /* * 上传文件 * 参数: * $bucket: 存储空间名称 * $object: 文件名 * $filePath: 文件路径 * 返回: * true: 上传成功 * false: 上传失败 */ public function uploadFile($object, $filePath) { try { $result = $this->ossClient->uploadFile($this->bucket, $object, $filePath); return true; // 上传成功返回true } catch (OssException $e) { return false; // 上传失败返回false并记录错误信息,例如:echo $e->getMessage(); } } }