Upload images in PHP yii2 interface

Source: Internet
Author: User
Now in the interface to iOS, encountered some picture upload problem, now can receive the iOS came from Base64 encoded data. Do I need to decode? How does decoding need to be processed to upload images to the server and retrieve URLs from the server to be stored in the database? Seek the guidance of the Great God. I am the interface written under the YII2 framework

Reply content:

Now in the interface to iOS, encountered some picture upload problem, now can receive the iOS came from Base64 encoded data. Do I need to decode? How does decoding need to be processed to upload images to the server and retrieve URLs from the server to be stored in the database? Seek the guidance of the Great God. I am the interface written under the YII2 framework

I used base64 when I was crafting canvas images on the front.
YII2 processing
1. Read the base64 encoded data "=" $data
2. $data = Base64_decode ($data);//data is the binary data.
3. Assume that there is a upload folder under the Web directory with the file name MD5 (Microtime (TRUE)). 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 from iOS, and the second one is the data that I base64_decode () output after decoding. These are the HTTP transmissions I simulated 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.