54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../init.php';
|
|
|
|
global $globalConfig;
|
|
|
|
$cosConfig = $globalConfig['COS'];
|
|
|
|
$bucket = $cosConfig['bucket'];
|
|
$secretId = $cosConfig['secretId'];
|
|
$secretKey = $cosConfig['secretKey'];
|
|
$region = $cosConfig['region'];
|
|
|
|
|
|
$cosClient = new Qcloud\Cos\Client(
|
|
array(
|
|
'region' => $region,
|
|
'schema' => 'https', //协议头部,默认为http
|
|
'credentials' => array(
|
|
'secretId' => $secretId,
|
|
'secretKey' => $secretKey,
|
|
)
|
|
)
|
|
);
|
|
|
|
try {
|
|
$result = $cosClient->listObjects(['Bucket' => $bucket]);
|
|
// 请求成功
|
|
if (isset($result['Contents'])) {
|
|
|
|
foreach ($result['Contents'] as $rt) {
|
|
if ($rt['StorageClass'] !== 'DEEP_ARCHIVE') {
|
|
$result = $cosClient->Copy(
|
|
$bucket,
|
|
$rt['Key'], //此处的 key 为对象键
|
|
[
|
|
'Region' => $region,
|
|
'Bucket' => $bucket,
|
|
'Key' => $rt['Key'],
|
|
],
|
|
[
|
|
'StorageClass' => 'DEEP_ARCHIVE'
|
|
]
|
|
);
|
|
var_dump($result);
|
|
}
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
var_dump($e);
|
|
}
|
|
|
|
|