: This article mainly describes how php uploads base64 encoded images to Qiniu. For more information about PHP tutorials, see. Recently, I have been studying how to upload base64 encoded images to Qiniu Cloud storage using php. Google has not found any answer for help, but can only study it on its own, new Year's Day is still hitting the code. I'm glad that the problem has been solved successfully. I 'd like to share my code with you:
UploadToken ($ bucket, null, 3600); // Obtain the tokenfunction 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, expires, $ 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 encoded string"; echo"";echo request_by_curl('http://upload.qiniu.com/putb64/-1',$str,$upToken);echo "";
Get is successful.
The above describes how php uploads base64 encoded images to Qiniu, including some content, and hopes to help friends who are interested in PHP tutorials.