Qiniu\Storage\BucketManager::copy PHP Method

copy() public method

给资源进行重命名,本质为move操作。
public copy ( $from_bucket, $from_key, $to_bucket, $to_key, $force = false ) : mixed
$from_bucket 待操作资源所在空间
$from_key 待操作资源文件名
$to_bucket 目标资源空间名
$to_key 目标资源文件名
return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
    public function copy($from_bucket, $from_key, $to_bucket, $to_key, $force = false)
    {
        $from = \Qiniu\entry($from_bucket, $from_key);
        $to = \Qiniu\entry($to_bucket, $to_key);
        $path = '/copy/' . $from . '/' . $to;
        if ($force) {
            $path .= '/force/true';
        }
        list(, $error) = $this->rsPost($path);
        return $error;
    }

Usage Example

示例#1
0
 /**
  * 复制文件到另外一个位置
  *
  * @param $fromBucket
  * @param $fromFile
  * @param $toBucket
  * @param $toFile
  * @return \Qiniu\Storage\成功返回NULL|string
  */
 public function copy($fromBucket, $fromFile, $toBucket, $toFile)
 {
     $bucketManager = new BucketManager($this->auth);
     $error = $bucketManager->copy($fromBucket, $fromFile, $toBucket, $toFile);
     if ($error !== null) {
         return $error;
     } else {
         return "Success";
     }
 }
All Usage Examples Of Qiniu\Storage\BucketManager::copy