I've created a canvas via jQuery and need to save it back to the public file directory as an image, so I can access it like any other image.
There are a lot of solutions posted all overI can create the place,file and I've tried all kinds of combinations with zero luck.
I havesave it, into the following jQuery aftersame file location as my save.php script, but unable to save it to the canvas has been created:public file directory...
var canvas = document.getElementById('myCanvas');
var dataURL = canvas.toDataURL("image/png");
$.ajax({
type: "POST",
url: "saveDrupal.settings.basePath + "mypath/save.php",
data: {
imgBase64: dataURL
}
})
Then the following php as called in save.php:
$img = $_POST['data'];$_POST['imgBase64'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$fileData = base64_decode($img);
$fileName = 'public://' . uniqid() . 'myCanvas.png';
file_put_contents($fileName, $fileData);
I've also tried with variations on theexcluding 'public://' .
will happily save script, such asto the location specified in Drupal.settings.basePath + "mypath/..."
, with no luck:
file_save_data($fileData);
Any ideas?but I'm unable to tell it to save to the public directory or even any directory structure...