How does php save base64 encoding to a local file?

Source: Internet
Author: User
The local code uses C ++ to encode an image in base64. after The post is submitted to the web server, php decodes the base64_decode and saves the image. Use the hexadecimal editor to view and compare the source file (local source file image), and find that the 0d-carriage return is lost after saving the file. Process...
  1. The local code uses C ++ to encode an image in base64. after The post is submitted to the web server, php decodes the base64_decode and saves the image. Use the hexadecimal editor to view and compare the source file (local source file image ).0d-- Carriage return.

  2. The problem encountered in the process is that the base64 encoded data + number obtained after post transmission _ POST ['data'] is changed to a space, and the phpstr_replace(...)Replace it with the original one. you can confirm that there is no problem.

  3. After$img = base64_decode(...)After decoding, the returnedstrlen($img)The length of the source file is the same as that of the source file. Whether it is usedfor(...) fwrite(...);Orfile_put_contents(...)All are missing bytes 0d

To be resolved: See the title. resolved: the process is correct when opening the file stream.

Reply content:
  1. The local code uses C ++ to encode an image in base64. after The post is submitted to the web server, php decodes the base64_decode and saves the image. Use the hexadecimal editor to view and compare the source file (local source file image ).0d-- Carriage return.

  2. The problem encountered in the process is that the base64 encoded data + number obtained after post transmission _ POST ['data'] is changed to a space, and the phpstr_replace(...)Replace it with the original one. you can confirm that there is no problem.

  3. After$img = base64_decode(...)After decoding, the returnedstrlen($img)The length of the source file is the same as that of the source file. Whether it is usedfor(...) fwrite(...);Orfile_put_contents(...)All are missing bytes 0d

To be resolved: See the title. resolved: the process is correct when opening the file stream.

You can directly output the image on the web to see if it can be displayed normally.

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.