rename() public méthode

给资源进行重命名,本质为move操作。
public rename ( $bucket, $oldname, $newname ) : mixed
$bucket 待操作资源所在空间
$oldname 待操作资源文件名
$newname 目标资源文件名
Résultat mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
 /**
  * 删除海报的文件夹
  **/
 function actiondelPosterdir()
 {
     $ret = array('status' => 0, 'mag' => '');
     try {
         $del_dir = Yii::app()->request->getParam("del_dir");
         $new_dir = Yii::app()->request->getParam("new_dir");
         if (empty($new_dir) || empty($del_dir) || $del_dir == $new_dir) {
             throw new Exception('传参失败');
         }
         $qiniu = new erp_qiniu();
         //七牛的接口类
         $brand_qiniu_account = $qiniu->getAccountByBrand($_SESSION['brandid']);
         //获取品牌的七牛子账号信息
         if (count($brand_qiniu_account) == 0) {
             throw new Exception('品牌暂未绑定七牛帐号');
         }
         $poster = new posterclass();
         //获取将要删除文件夹下的所有图片
         $p_w = array();
         $p_w['dirname'] = $del_dir;
         $poster_ret = $poster->select_all_poster($_SESSION['brandid'], -1, $p_w);
         if ($poster_ret['page_sum'] > 0) {
             //获取品牌的七牛权限
             $atch = new Auth($brand_qiniu_account[0]['access_key'], $brand_qiniu_account[0]['secret_key']);
             //创建七牛资源类
             $Bucket = new BucketManager($atch);
             foreach ($poster_ret['data'] as $value) {
                 $new_url = strtr($value['url'], array('/' . $del_dir . '/' => '/' . $new_dir . '/'));
                 //修改图片路径
                 $Bucket_ret = $Bucket->rename($brand_qiniu_account[0]['space'], $value['url'], $new_url);
                 if (empty($Bucket_ret)) {
                     //没有返回值 表示修改成功
                     $poster->up_poster($value['id'], array('url' => $new_url, 'dirname' => $new_dir));
                 }
             }
         }
         $ret['status'] = 1;
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     echo json_encode($ret);
 }
 /**
  * {@inheritdoc}
  */
 public function rename($path, $newpath)
 {
     $r = $this->bucketManager->rename($this->bucket, $path, $newpath);
     return is_null($r);
 }
Exemple #3
0
 /**
  * 重命名
  * @param $oldFileName
  * @param $newFileName
  * @return mixed
  */
 public function rename($oldFileName, $newFileName)
 {
     $client = new BucketManager($this->auth);
     return $client->rename($this->bucket, $oldFileName, $newFileName);
 }