php遍历阿里云oss文件 批量删除一个目录下的所有文件

正文开始

[md]

//需要删除的文件夹路径
$file_url_server = 'demo/removeDir/';
//引用jdk
        require_once(ROOT_PATH .'vendor/ali_oss/samples/Common.php');
        $bucketName = \Common::getBucketName();
        $ossClient = \Common::getOssClient();
        $file_url_server = rtrim($file_url_server, '/').'/';

 $options = [
            'delimiter' => '/',
            'prefix' => $file_url_server,
            'max-keys' => 1000, //最多1000个
            'marker' => '',
        ];
        //获取文件列表
        $response = $ossClient->listObjects($bucketName, $options);
        $fileList = $response->getObjectList();
        $delObj = [];
        foreach ($fileList as $v) {
            $keyName = $v->getKey();
            $delObj[] = $keyName;
        }
        if($delObj) {
            $ossClient->deleteObjects($bucketName, $delObj);
        }

正文结束

PHP接口(interface)和抽象类(abstract) php cli模式自动释放内存