Skip to content

Commit b8539f6

Browse files
committed
Add changeStatus
1 parent cb13105 commit b8539f6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

examples/rs_change_status.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
$key = "qiniu.jpg";
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
$status = 1;//0表示启用;1表示禁用
16+
17+
$err = $bucketManager->changeStatus($bucket, $key, $status);
18+
if ($err) {
19+
print_r($err);
20+
}

src/Qiniu/Storage/BucketManager.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,23 @@ public function changeType($bucket, $key, $fileType)
225225
return $error;
226226
}
227227

228+
/**
229+
* 修改文件的存储状态,即禁用状态和启用状态间的的互相转换
230+
*
231+
* @param $bucket 待操作资源所在空间
232+
* @param $key 待操作资源文件名
233+
* @param $status 待操作文件目标文件类型
234+
*
235+
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
236+
* @link https://developer.qiniu.com/kodo/api/4173/modify-the-file-status
237+
*/
238+
public function changeStatus($bucket, $key, $status)
239+
{
240+
$resource = \Qiniu\entry($bucket, $key);
241+
$path = '/chstatus/' . $resource . '/status/' . $status;
242+
list(, $error) = $this->rsPost($path);
243+
return $error;
244+
}
228245

229246
/**
230247
* 从指定URL抓取资源,并将该资源存储到指定空间中

0 commit comments

Comments
 (0)