Hope someone help me with this mess. I am building a little mobile app that transforms a series of canvas objects to dataUrl then it encodes the data with btoa() method:
var canvas = document.getElementById("imagen_envio");
var dataUrl = canvas.toDataURL('image/jpeg', .7);
var file = btoa(dataUrl);
After that it sends the file to a php file at the server using AJAX to store it in a Medium BLOB at MySQL. Everything it's working fine to this point but after that a php file must display the images but it's not working:
link: http://a.gob.mx/PHP_tratayretrata/img.php
//img.php
$connect = mysqli_connect($host, $user ,$password) or die("No se pudo conectar.");
mysqli_select_db($connect,$DB) or die("No se encuentra la base.");
$sql = "SELECT img FROM fotos WHERE usuario = 1 AND tema = 1 AND ejercicio = 1";
$result=mysqli_query($connect, $sql);
$row=mysqli_fetch_array($result);
header("Content-type: image/jpeg; charset=UTF-8");
$img = base64_decode($row["img"]);
echo '<img src="'.$img.'"/>';
?>
I made another php file that prints the data to text: http://a.gob.mx/PHP_tratayretrata/print-data.php and I used that data in a simple html file to be sure that the data is not corrupted: http://a.gob.mx/PHP_tratayretrata/test-data.html and it works!
So I have no idea what am I doing wrong. Any ideas? Thanks in advance!