test_service d3170b4d1c 1
2023-12-01 15:43:29 +08:00

61 lines
1.4 KiB
PHP
Executable File

<?php
namespace hema\storage\engine;
use OSS\OssClient;
use OSS\Core\OssException;
/**
* 阿里云存储引擎 (OSS)
* Class Aliyun
*/
class Aliyun extends Basics
{
/**
* 执行上传
* @return bool|mixed
*/
public function upload()
{
try {
$ossClient = new OssClient(
$this->config['access_key_id'],
$this->config['access_key_secret'],
$this->config['domain'],
true
);
$result = $ossClient->uploadFile(
$this->config['bucket'],
$this->getSaveFileInfo()['file_path'],
$this->getRealPath()
);
} catch (OssException $e) {
$this->error = $e->getMessage();
return false;
}
return true;
}
/**
* 删除文件
* @param string $fileName
* @return bool|mixed
*/
public function delete(string $fileName)
{
try {
$ossClient = new OssClient(
$this->config['access_key_id'],
$this->config['access_key_secret'],
$this->config['domain'],
true
);
$ossClient->deleteObject($this->config['bucket'], $fileName);
} catch (OssException $e) {
$this->error = $e->getMessage();
return false;
}
return true;
}
}