北方地区上传报错,incorrect zone, please use up-z1.qiniu.com
【摘要】
Qiniu.php 文件中,两个重要方法
/** * Qiniu constructor. * @param $accessKey * @param $secretKey * @param $domain * @param string $bucket * @param string ...
Qiniu.php 文件中,两个重要方法
-
/**
-
* Qiniu constructor.
-
* @param $accessKey
-
* @param $secretKey
-
* @param $domain
-
* @param string $bucket
-
* @param string $zone 默认华南机房
-
*/
-
function __construct($accessKey, $secretKey, $domain, $bucket, $zone = 'south_china')
-
{
-
$this->accessKey = $accessKey;
-
$this->secretKey = $secretKey;
-
$this->domain = $domain;
-
$this->bucket = $bucket;
-
-
$config = $this->zoneConfig($zone);
-
-
$this->up_host = $config['up'][0]; //读取第一个可用线路
-
-
-
}
-
protected function zoneConfig($key = null)
-
{
-
$arr = [
-
//华东
-
'east_china' => [
-
'up' => array("up.qiniup.com", 'up-nb.qiniup.com', 'up-xs.qiniup.com'),
-
],
-
//华北
-
'north_china' => [
-
'up' => array('up-z1.qiniup.com'),
-
],
-
//华南机房
-
'south_china' => [
-
'up' => array('up-z2.qiniup.com', 'up-gz.qiniup.com', 'up-fs.qiniup.com'),
-
],
-
//北美机房
-
'north_america' => [
-
'up' => array('up-na0.qiniup.com'),
-
]
-
];
-
if ($key !== null) {
-
if (isset($arr[$key])) {
-
return $arr[$key];
-
} else {
-
throw new \Exception('区域不存在');
-
}
-
}
-
return $arr;
-
}
默认使用的是华南机房;所以在调用的时候,改用华北机房就好
$qiniu = new Qiniu(Product::AK, Product::SK, Product::DOMAIN, Product::BUCKET,'north_china');
-
//上传图片
-
public function upload()
-
{
-
if ($_FILES['Product']['error']['cover'] > 0) {
-
return false;
-
}
-
-
$qiniu = new Qiniu(Product::AK, Product::SK, Product::DOMAIN, Product::BUCKET,'north_china');
-
$key = uniqid();
-
$qiniu->uploadFile($_FILES['Product']['tmp_name']['cover'], $key);
-
$cover = $qiniu->getLink($key);
-
$pics = [];
-
foreach ($_FILES['Product']['tmp_name']['pics'] as $k => $file) {
-
if ($_FILES['Product']['error']['pics'][$k] > 0) {
-
continue;
-
}
-
$key = uniqid();
-
$qiniu->uploadFile($file, $key);
-
$pics[$key] = $qiniu->getLink($key);
-
}
-
-
return ['cover' => $cover, 'pics' => json_encode($pics)];
-
}
文章来源: blog.csdn.net,作者:lxw1844912514,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/lxw1844912514/article/details/113542498
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)