百度云存储 批量删除 清空脚本
实现清空百度云存储指定bucket下的全部 object
就是文件……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?php ob_flush(); flush(); //require_once 'bcs.class.php'; //非BAE环境下需要引用bcs.class.php $host = 'bcs.duapp.com'; $ak = getenv ( 'HTTP_BAE_ENV_AK' ); //如果不在BAE环境下,请自行填写ak,下面sk同 $sk = getenv ( 'HTTP_BAE_ENV_SK' ); $bucket = 'test'; //此处填写bucket function delete_object($baidu_bcs) { global $bucket; $opt = array ( 'start' => 0); $response = $baidu_bcs->list_object ( $bucket, $opt ); $body = $response->body; $str = json_decode($body,true); $i = 0; while($i<300){ //此处根据bucket中object数量填写 $object= $str["object_list"][$i]["object"]; $response = $baidu_bcs->delete_object ( $bucket, $object ); ob_flush(); flush(); echo $object; echo ' '; echo $response->isOK () ? "OK\n" : "NOT OK\n"; echo '<br>'; $i++; } } $baidu_bcs = new BaiduBCS ( $ak, $sk, $host ); delete_object($baidu_bcs); ob_flush(); flush(); ?> |