μλ νμΈμ, μλͺ μ png μ΄λ―Έμ§μ κ°μ μλ² νμΌμ μ μ₯νλ €κ³ νλλ° μ΄λ»κ² ν΄μΌ ν μ§ λͺ¨λ₯΄κ² μ΅λλ€(λ΄ μ ν리μΌμ΄μ μμ phpμ javascriptλ₯Ό μ¬μ©νκ³ μμ΅λλ€).
κ°μ¬ν©λλ€!
μ΄ μ½λλ‘ ν΄κ²°:
if (isset($_POST['imageData'])) {
$imgData = base64_decode($_POST['imageData']);
$image_name= $_POST['image_name'];
// Path where the image is going to be saved
$filePath = '../img/'.$image_name.'.jpg';
// Delete previously uploaded image
if (file_exists($filePath)) { unlink($filePath); }
// Write $imgData into the image file
$file = fopen($filePath, 'w');
fwrite($file, $imgData);
fclose($file);
} else {
echo "imgData doesn't exists";
}
μλ
,
κ°μ λ¬Έμ κ° μμ§λ§ μ΄λμ μ½λλ₯Ό μΆκ°ν΄μΌ ν©λκΉ?
κ°μ¬ν©λλ€!
μλ νμΈμ @stupendomen
μ΄μ μ½λλ‘ μ .php νμΌ(signature_pad.php)μ λ§λ€κ³ μλͺ
ν¨λκ° ν¬ν¨λ νμΌμμ ajax ν¨μλ‘ νΈμΆν©λλ€(μ μ₯ λ²νΌμ λΉκΈΈ λ).
μ΄ κ°μ:
`
var λνΌ = document.getElementById("μλͺ
ν¨λ"),
clearButton = wrapper.querySelector("[λ°μ΄ν° μμ
= μ§μ°κΈ°]"),
saveButton = wrapper.querySelector("[λ°μ΄ν° μμ
=μ μ₯]"),
μΊλ²μ€ = wrapper.querySelector("μΊλ²μ€"),
μλͺ
ν¨λ;
// Adjust canvas coordinate space taking into account pixel ratio,
// to make it look crisp on mobile devices.
// This also causes canvas to be cleared.
function resizeCanvas() {
// When zoomed out to less than 100%, for some very strange reason,
// some browsers report devicePixelRatio as less than 1
// and only part of the canvas is cleared then.
var ratio = Math.max(window.devicePixelRatio || 1, 1);
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
}
window.onresize = resizeCanvas;
resizeCanvas();
signaturePad = new SignaturePad(canvas);
clearButton.addEventListener("click", function (event) {
signaturePad.clear();
});
saveButton.addEventListener("click", function (event) {
event.preventDefault();
var nombre_receptor_form = $("#nombre_receptor_form").val();
var id_nombre_imagen = $("#id_nombre_imagen").val();
if ( signaturePad.isEmpty() ) {
alert("Please insert signature.");
} else {
var dataUrl = signaturePad.toDataURL();
document.getElementById('imagen_firma').src = dataUrl;
var imagen = dataUrl.replace(/^data:image\/(png|jpg);base64,/, "");
$.ajax({
url: './includes/signature_pad.php',
type: 'POST',
data: {
imageData: imagen
},
})
.done(function(msg) {
// Image saved successfuly.
console.log("success: " + msg);
document.getElementById("my_form").submit(); //I do this to save other information.
})
.fail(function(msg) {
console.log("error: " + msg);
});
`
λλ μ΄κ²μ΄ λΉμ μκ² μ μ©νκΈ°λ₯Ό λ°λλλ€!
μλ²½ν!
κ°μ¬ ν΄μ
@davidosuna1987 μ΄ λ μ€μ μ΄λμ λμ¨ κ±΄κ°μ?
var form_receiver_name = $("#form_receiver_name").val();
var id_image_name = $("#id_image_name").val();
@davidosuna1987 @stupendomen λ¬Έμ κ° μμ΅λλ€! μμ μ½λλ₯Ό μ ννκ² λ³΅μ¬νκ³ dbconenct.php νμΌμ μΆκ°νμ§λ§ μ΄ μμ μ μννλ λ°©λ²μ 보μ¬μ€ μ μμ΅λκΉ? μ΅λν 빨리 λμμ£ΌμΈμ
μ 체 μ½λλ₯Ό κ²μν μ μμ΅λκΉ? μ λ°
κ°μ¬ν©λλ€!
κ°μ¬ ν΄μ. κ΅μ₯ν μ μ©νλ€ !
κ°μ¬ν©λλ€!
@davidosuna1987
μ’μ΅λλ€. κΈ°μ¬ν΄ μ£Όμ
μ κ°μ¬ν©λλ€.
κ·Έλ¬λ μ λ²μ μ SignaturePadλ μ΄μ λ²μ μμλ μλνλλ‘ λ§λ€ μ μμμ΅λλ€.
λκ΅°κ° PHPμμ μ¬μ© μλ₯Ό λ£μ μ μμ΅λκΉ?
λ§€μ° κ°μ¬ν©λλ€
κ°μ₯ μ μ©ν λκΈ
μλ νμΈμ @stupendomen
μ΄μ μ½λλ‘ μ .php νμΌ(signature_pad.php)μ λ§λ€κ³ μλͺ ν¨λκ° ν¬ν¨λ νμΌμμ ajax ν¨μλ‘ νΈμΆν©λλ€(μ μ₯ λ²νΌμ λΉκΈΈ λ).
μ΄ κ°μ:
`
var λνΌ = document.getElementById("μλͺ ν¨λ"),
clearButton = wrapper.querySelector("[λ°μ΄ν° μμ = μ§μ°κΈ°]"),
saveButton = wrapper.querySelector("[λ°μ΄ν° μμ =μ μ₯]"),
μΊλ²μ€ = wrapper.querySelector("μΊλ²μ€"),
μλͺ ν¨λ;
`
λλ μ΄κ²μ΄ λΉμ μκ² μ μ©νκΈ°λ₯Ό λ°λλλ€!