I want to save a base64 string as an image (.png or .jpg) on my server.
The string I get looks like this: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQA[...]"
I tried this:
$data = $_POST['form_new_data'];
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents("/userImgs/pic.jpg",$data);
but it is not working (maybe because the base64 string is a jpeg?).. Please help..