javascript - Callback unique filename with jquery php -
i using html2canvas , canvas2image create png image canvas , save server unique filename.
i know how retrieve , show unique filename after gets generated.
jquery
$(function() { $("#convertcanvas").click(function() { html2canvas($("#mycanvas"), { onrendered: function(canvas) { thecanvas = canvas; document.body.appendchild(canvas); // convert sharing var img = canvas.todataurl("image/png",1.0); $.ajax({ url:'save.php', type:'post', data:{ data:img } });
php
<?php $data = $_post['data']; $data = substr($data,strpos($data,",")+1); $data = base64_decode($data); $file = 'images/myfile'.md5(uniqid()).'.png'; file_put_contents($file, $data); ?>
thanks in advance help.
you can filename returning in php , catching in ajax succes
method.
php
<?php $data = $_post['data']; $data = substr($data,strpos($data,",")+1); $data = base64_decode($data); $filename = 'myfile'.md5(uniqid()).'.png'; // <-- added because don't want return image folder. $path = 'images/'.$filename; file_put_contents($path, $data); echo $filename; // <-- echo new filename! ?>
jquery
$.ajax({ url:'save.php', type:'post', data:{ data:img }, success: function(data) { alert(data); // <-- here filename handledata(data); } });
Comments
Post a Comment