Qiniu\Storage\BucketManager::fetch PHP Method

fetch() public method

从指定URL抓取资源,并将该资源存储到指定空间中
public fetch ( $url, $bucket, $key = null ) : array
$url 指定的URL
$bucket 目标资源空间
$key 目标资源文件名
return array 包含已拉取的文件信息。 成功时: [ [ "hash" => "", "key" => "" ], null ] 失败时: [ null, Qiniu/Http/Error ]
    public function fetch($url, $bucket, $key = null)
    {
        $resource = \Qiniu\base64_urlSafeEncode($url);
        $to = \Qiniu\entry($bucket, $key);
        $path = '/fetch/' . $resource . '/to/' . $to;
        $ak = $this->auth->getAccessKey();
        $ioHost = $this->zone->getIoHost($ak, $bucket);
        $url = $ioHost . $path;
        return $this->post($url, null);
    }

Usage Example

Example #1
0
<?php

require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);
$bmgr = new BucketManager($auth);
$url = 'http://php.net/favicon.ico';
$bucket = 'Bucket_Name';
$key = time() . '.ico';
list($ret, $err) = $bmgr->fetch($url, $bucket, $key);
echo "=====> fetch {$url} to bucket: {$bucket}  key: {$key}\n";
if ($err !== null) {
    var_dump($err);
} else {
    echo 'Success';
}
All Usage Examples Of Qiniu\Storage\BucketManager::fetch