Skip to content
Advertisement

Base64 image string into image file using PHP

I need code to convert a base64 image string into an image file and write into local directory using PHP. I tried:

JavaScript

It is writing a file with given extension, but when you try to open file it shows an invalid file error.

Advertisement

Answer

I figure it out the solution.

JavaScript

I was sending over the API to PHP server. You need to encode your image base64 string and your image base64 string must include “data:image/jpeg;base64”. We are splitting it on PHP server But don’t think to send image base54 without “data:image/jpeg;base64”.
But remember one thing you have to use image base64 including

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement