I have a canvas converted into a data url, and I need to save it locally in my server. For some reason I can't get this (simple) thing to work. It doesn't write any file on "natalisations" folder. The folder as the write permissions, and javascript seems to do it's work fine and with no errors. Php doesn't give me any error, just doesn't write the actual file.
Javascript
function postData(data) {
alert(data);
$.ajax({
type: "POST",
url: "uploadaux.php",
data: {image: data}
}).done(function( respond ) {
alert(respond);
});
the output of alert(data) is "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAg(...)"
This is the uploadaux.php file:
if ( isset($_POST["image"]) && !empty($_POST["image"]) ) {
$dataURL = $_POST["image"];
$parts = explode(',', $dataURL);
$data = $parts[1];
$data = base64_decode($data);
$fp = fopen('natalisations/image.jpg', 'w');
fwrite($fp, $data);
fclose($fp);
}
I've been debugging this for ages... and no sign of finding a solution. Thanks in advance!