Image upload in phpyii2 interface

Source: Internet
Author: User
Now I am sending an interface to ios and have encountered some image upload problems. now I can receive base64 encoded data from ios. Do I need to decode it? What should I do for decoding to upload images to the server and obtain URLs from the server to store them in the database? Please kindly advise. I am now giving an interface to ios and have encountered some image upload problems. now I can receive base64 encoded data from ios. Do I need to decode it? What should I do for decoding to upload images to the server and obtain URLs from the server to store them in the database? Please kindly advise. I am writing an interface in the yii2 framework.

Reply content:

Now I am sending an interface to ios and have encountered some image upload problems. now I can receive base64 encoded data from ios. Do I need to decode it? What should I do for decoding to upload images to the server and obtain URLs from the server to store them in the database? Please kindly advise. I am writing an interface in the yii2 framework.

I used base64 for canvas image synthesis at the front end.
Yii2 processing
1. read base64 encoded data => $ data
2. $ data = base64_decode ($ data); // data is binary data
3.assume that the Web Directory contains an uploadfolder with the file name md5(microtime(true00000000.'.jpg '=> $ filename
4. file_put_contents (Yii: $ app-> basePath. '/web/upload/'. $ filename, $ data );
5. url = Yii: $ app-> urlManager-> createAbsoluteUrl (['/']). 'upload/'. $ filename

The first figure is the base64 encoded data sent from ios, and the second figure is the data output after base64_decode () decoding. These are the http transmission I simulate on postman. Why is the decoded data garbled?

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.