public function base64_oss($item = [])
{
if ($item) {
$localFilename = $item['image']; //数据库中位置
$localDir = ROOT_PATH; //前边的全路径
$serviceDir = 'uploads/';//OSS服务器上保存的位置
// $img_path = str_replace('../../..', '', $item['image']);
// // $object = $img_path;//想要保存文件的名称
// $file = $img_path;//本地文件路径
// dump($file);exit;
try {
$config = get_addon_config('alioss');
$OssClient = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint']);
//文件绝对路径
@file_put_contents('public/log/aidraw/' . date('Y-m-d') . '.txt', __FUNCTION__ . ' gaiyxia At process order_id = ' . ROOT_PATH . 'public/' . $localFilename . Date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);
//$result = $OssClient->uploadFile($config['bucket'], $object, $file);
$result = $OssClient->uploadFile($config['bucket'], $serviceDir . $localFilename, $localDir . 'public/' . $localFilename);
//上传成功
$return_path = $result['info']['url'];
// dump($return_path);exit;
//这里可以删除上传到本地的文件。
// unlink($file);
} catch (OssException $e) {
//上传失败
return [0, $e->getMessage()];
}
return [1, $return_path];
}
}
php 本地图片存到oss
于 2023-05-20 17:42:56 首次发布