Fork me on GitHub

PHP删除七牛云源文件

一、调用前需引入七牛云sdk

二、删除单个文件

 //封装的方法
    require ('../../methods/public_methods.php');
    require('../../methods/qiniu_sdk/autoload.php');
    use Qiniu\Auth;
    //获取参数
    $img_key=var_is_null2('post','$img_key');//获取参数
    // 用于签名的公钥和私钥
    $accessKey = '你的accessKey';
    $secretKey = '你的secretKey ';
    $bucket='你的空间名';
    $key = $img_key;
    $auth = new Auth($accessKey, $secretKey);
    $config = new \Qiniu\Config();
    $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
    $err = $bucketManager->delete($bucket, $key);
    if ($err) {
        print_r($err);
    }

三、批量删除文件

    //封装的方法
    require ('../../methods/public_methods.php');
    require('../../methods/qiniu_sdk/autoload.php');
    use Qiniu\Auth;
    //获取参数
    $del_img_arr=var_is_null2('post','del_img_arr');//获取参数
    // 用于签名的公钥和私钥
    $accessKey = '你的accessKey';
    $secretKey = '你的secretKey';
    $bucket='你的空间名';
    $auth = new Auth($accessKey, $secretKey);
    $config = new \Qiniu\Config();
    $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
    //每次最多不能超过1000个
    $keys = $del_img_arr;//包含key的数组集合
    $ops = $bucketManager->buildBatchDelete($bucket, $keys);
    list($ret, $err) = $bucketManager->batch($ops);
    if ($err) {
        print_r($err);
    } else {
        print_r($ret);
    }

四、封装

 

 OVER!

 

posted @ 2022-09-08 17:35  三冬两夏  阅读(274)  评论(0编辑  收藏  举报