I'm currently working on an PHP- Function, that's called via AJAX. It turns Base64- Strings into images. The Problem is, that the ajax call echoes the base64- String to the Front- End, instead of just my other output.
The image gets created on the Server, no Problem at all. But on the site, where you start this action (via an ajax- call) returns not only the
"done <br />"
but also the whole base64- String of the image.
The AJAX Call looks like this:
jQuery(document).ready(function($) {
$('#lii-form').submit(function() {
data = {
action: 'lii_map_images'
};
$.post(ajaxurl, data, function(response){
$('#lii_log').html(response);
});
return false;
});
});
The PHP- Function looks like this: (Everything works, except for the base64- string- output [which shouldn't output])
$imgUrl = $aduser -> getFoto();
$imgUrl = substr( $imgUrl, 0, -3 );
error_log($imgUrl); // tried it without this line, still prints
// turn String to image
$data = str_replace('data:image/jpeg;base64,', '', $base64_string);
$data = str_replace(' ', '+', $data);
$data = base64_decode($data);
$img_data = imagecreatefromstring($data);
$file = $uploaddir."/".$filename;
imagejpeg($img_data, $file);
imagedestroy($img_data);
echo "done <br />";
I'm working with Wordpress, btw.
EDIT
The output looks like this:
EDIT 2
I tried to remove the response from the ajax call:
$.post(ajaxurl, data, function(response){
$('#lii_log').html(response);
});
to
$.post(ajaxurl, data, function(response){
});
but it still showed the image data.
EDIT 3
The Image- data seems to be more of a raw jpeg data than base64.