var name = $("#name").val();
$.ajax({
type: "post",
dataType: "json",
url: "save.php",
data: {
image: canvas.toDataURL(),
name:name
}
});
I'm trying to save my cropped image with name from get text field.
When I sent only imageurl
its working. How can I fix this problem ?
save.php:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
// location to save cropped image,
$ad=$_POST['name'];
$url = 'temp/"'.$ad.'".jpg';
//$url = 'temp/one.jpg';
// remove the base64 part
$base64 = preg_replace('#^data:image/[^;]+;base64,#', '', $_POST['image']);
$base64 = base64_decode($base64);
$source = imagecreatefromstring($base64); // create
imagejpeg($source, $url, 100); // save image
// return URL
$validation = array (
'url' => $url);
echo json_encode($validation);
}