php向七牛上传base64编码的图片
最近一直在研究如何通过php向七牛云存储上传base64编码的图片,求助百度,谷歌都没有找到答案,无奈只能自己研究,元旦还在敲代码也算是够狠的,值得高兴的是成功解决了该问题,与大家分享一下我的代码:
<?php require_once 'vendor/autoload.php'; header('Access-Control-Allow-Origin:*'); use Qiniu\Auth; $bucket = '要上传的空间名'; $accessKey = '你的accessKey'; $secretKey = '你的secretKey'; $auth = new Auth($accessKey, $secretKey); $upToken = $auth->uploadToken($bucket, null, 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 "<pre>"; echo request_by_curl('http://upload.qiniu.com/putb64/-1',$str,$upToken); echo "</pre>";
成功get。
相关推荐
hedongli 2020-09-01
pythonjw 2020-11-17
浪味仙 2020-08-17
IT兄弟团 2020-08-01
凉白开 2020-07-19
kjh00abc 2020-07-08
Skyline 2020-06-28
苦咖啡flask 2020-06-18
万物weiyi 2020-06-16
半纸药笺 2020-06-14
chenhaimeimeng 2020-06-13
JF0 2020-06-13
逍遥友 2020-06-02
kyelu 2020-06-02
northwindx 2020-05-31
tengyuan 2020-05-30
singer 2020-05-30
GreatZhou 2020-05-28
coolhty 2020-05-20