Php uploads base64 encoded images to Qiniu

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.