安装PHP SDK
'access' => 'YOUR_ACCESS_KEY','secret' => 'YOUR_SECRET_KEY','bucket' => 'YOUR_BUCKET','domain' => 'https://images.your_domain.com'
];
$auth = new Auth($cfg['access'],$cfg['secret']);
// 创建一个过期时间为1小时的临时上传令牌
$token = $auth->uploadToken($cfg['bucket'],null,3600);
$filePath = "./illustration.png";
$uploadMgr = new UploadManager();
list($ret,$err) = $uploadMgr->putFile($token,$filePath);
if($err !== null) {
$this->err = $err;
} else {
echo $cfg['domain'] . '/' . $ret['key'];
}
$bucket = '要上传的空间名';
$accessKey = '你的accessKey';
$secretKey = '你的secretKey';
$auth = new Auth($accessKey,$secretKey);
$upToken = $auth->uploadToken($bucket,3600);//获取上传所需的token
function request_by_curl($remote_server,$post_string,$upToken) {
$headers = array();
$headers[] = 'Content-Type:image/png';
$headers[] = 'Authorization:UpToken '.$upToken;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$remote_server);
//curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_string);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch,CURLOPT_TIMEOUT,30);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$str="base64编码的字符串";
echo "
";";
echo request_by_curl('http://upload.qiniu.com/putb64/-1',$str,$upToken);
echo "
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。