当前位置:网站首页>oss删除当前时间前两天的所有文件
oss删除当前时间前两天的所有文件
2022-07-26 14:40:00 【小黑雷】
直接贴上脚本代码,反正都是几乎看阿里云案例搞得,没撒就是方便别人免得重复造轮子罢了,
require_once 就是引入阿里云oss 的包,
例举:如果哪个项目引入了阿里云oss,大部分composer引入都是在vendors目录下,那么可以直接,require_once '/www/wwwhtml/项目目录/vendor/aliyuncs/oss-sdk-php/autoload.php';
<?php
require_once './aliyun-oss-php-sdk-master/autoload.php';
static $oss = [
'key'=>'',
'secret'=>'',
'end_point'=>'http://oss-cn-shenzhen.aliyuncs.com',
'ALI_OSS_READ_URL'=>'',
'BUCKET'=>''
];
try {
$ossClient = new \OSS\OssClient($oss['key'], $oss['secret'], $oss['end_point']);
} catch (\OSS\Core\OssException $e) {
print $e->getMessage();
return;
}
try {
$listObjectInfo = $ossClient->doesBucketExist($oss['BUCKET']);
} catch (\OSS\Core\OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
$path = "audiores/".date("Ymd",strtotime("-2 day")).'/';
try{
(boolean) $exist = $ossClient->doesObjectExist($oss['BUCKET'], $path);
if(!$exist){
return 'ok';
}
} catch(\OSS\Core\OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
echo "333333333333333";
return;
}
$options = array(
\OSS\OssClient::OSS_MAX_KEYS => 200,
\OSS\OssClient::OSS_PREFIX => $path,
);
try {
$listObjectInfo = $ossClient->listObjects($oss['BUCKET'], $options);
} catch (\OSS\Core\OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
/**
* @param \OSS\Model\ObjectListInfo $listObjectInfo
* @param $ossClient
* @param $oss
*/
function extracted(\OSS\Model\ObjectListInfo $listObjectInfo,$ossClient,$oss):void
{
$prefixList = $listObjectInfo->getPrefixList();
// commonPrefixs列表中显示的是fun目录下的所有子文件夹。
if (!empty($prefixList)) {
foreach ($prefixList as $prefixInfo) {
$options = array(
\OSS\OssClient::OSS_MAX_KEYS => 200,
\OSS\OssClient::OSS_PREFIX => $prefixInfo->getPrefix(),
);
$listSubjectObjectInfo = $ossClient->listObjects($oss['BUCKET'], $options);
extracted($listSubjectObjectInfo,$ossClient,$oss);
}
}
$objectList = $listObjectInfo->getObjectList();
$data=[];
if (!empty($objectList)) {
foreach ($objectList as $objectInfo) {
$data[] = $objectInfo->getKey();
}
$delObjects = $ossClient->deleteObjects($oss['BUCKET'], $data);
foreach ($delObjects as $info){
$obj = strval($info);
}
}
}
extracted($listObjectInfo,$ossClient,$oss);
return 'ok';边栏推荐
- Figure introduction to neural network core dataset
- Seata deployment and microservice integration
- 中部“第一城”,长沙“人才引力”从争先到领先
- C winfrom common function integration
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
- Create root permission virtual environment
- 笔记(5)
- C# Winfrom 常用功能整合
- Minecraft 1.16.5 module development (52) modify the original biological trophy (lot table)
- php反序列化部分学习
猜你喜欢

One stop monitoring of the software and hardware infrastructure of the whole university, and Suzhou University replaces PostgreSQL with time series database

Establishment of SSO single sign on environment based on CAS

Embedded development: skills of debugging embedded software

【无标题】

Wechat applet - "do you really understand the use of applet components?

The development of smart home industry pays close attention to edge computing and applet container technology

llcc68广播唤醒简单说明

When AI encounters life and health, Huawei cloud builds three bridges for them

SiamRPN++:深层网络连体视觉跟踪的演变
![[solution of ordinary differential equation and drawing solution of small boat walking track]](/img/2d/3fd7e23fdbd0f343e740a5b93bf9d9.png)
[solution of ordinary differential equation and drawing solution of small boat walking track]
随机推荐
As the "first city" in Central China, Changsha's "talent attraction" has changed from competition to leadership
WPF common function integration
Lean product development: principles, methods and Implementation
31. Opinion-based Relational Pivoting forCross-domain Aspect Term Extraction 阅读笔记
Canvas laser JS special effect code
【整数规划】
Fill in the questionnaire and receive the prize | we sincerely invite you to fill in the Google play academy activity survey questionnaire
How to evaluate the test quality?
14. Bridge-Based Active Domain Adaptation for Aspect Term Extraction 阅读笔记
精益产品开发:原则、方法与实施
RPN:Region Proposal Networks (区域候选网络)
When AI encounters life and health, Huawei cloud builds three bridges for them
基于CAS的SSO单点服务端配置
C # use shift > > and operation and & to judge whether the two binary numbers have changed
Leetcode summary
智能家居行业发展,密切关注边缘计算和小程序容器技术
什么是传输层协议TCP/UDP???
【2022国赛模拟】白楼剑——SAM、回滚莫队、二次离线
VBA 上传图片
【干货】MySQL索引背后的数据结构及算法原理