123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- require dirname(__FILE__) . '/../vendor/autoload.php';
- $secretId = "SECRETID";
- $secretKey = "SECRETKEY";
- $region = "ap-beijing";
- $cosClient = new Qcloud\Cos\Client(
- array(
- 'region' => $region,
- 'schema' => 'https',
- 'credentials'=> array(
- 'secretId' => $secretId ,
- 'secretKey' => $secretKey)));
- $cos_path = "cos/folder";
- $nextMarker = '';
- $isTruncated = true;
- while ( $isTruncated ) {
- try {
- $result = $cosClient->listObjects(
- ['Bucket' => 'examplebucket-125000000',
- 'Delimiter' => '',
- 'EncodingType' => 'url',
- 'Marker' => $nextMarker,
- 'Prefix' => $cos_path,
- 'MaxKeys' => 1000]
- );
- $isTruncated = $result['IsTruncated'];
- $nextMarker = $result['NextMarker'];
- foreach ( $result['Contents'] as $content ) {
- $cos_file_path = $content['Key'];
- $local_file_path = $content['Key'];
-
- try {
- $cosClient->deleteObject(array(
- 'Bucket' => 'examplebucket-125000000',
- 'Key' => $cos_file_path,
- ));
- echo ( $cos_file_path . "\n" );
- } catch ( \Exception $e ) {
- echo( $e );
- }
- }
- } catch ( \Exception $e ) {
- echo( $e );
- }
- }
|