Using jQuery plugin called cropper, I am able to retrieve the cropped image as blob object. Now I need to save this blob object as a file on my server. The code for that is:
$('#image').cropper('getCroppedCanvas').toBlob(function (blob) {
var formData = new FormData();
formData.append('croppedImage', blob);
formData.append('form_key', window.FORM_KEY);
$.ajax('/upload.php', {
method: "POST",
data: formData,
processData: false,
contentType: false,
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
}
});
});
Here is my upload.php:
<?php
$blob = $_POST['croppedImage'];
//return $blob;
file_put_contents('/media/crop_products/test.png', $blob);
?>
It is not saving it on the server. What I am dong here? This request is made from an admin page in magento.