如果有人偶然发现了相同的问题,这就是我的解决方法:
问题取决于以下事实:大多数服务器将
+URL中的URL解释为编码空间(例如
%20)。因此,我需要先对数据进行编码,然后将其发送
POST到我指定的PHP函数。
这是我的代码:
Javascript
function screenShot(id) { html2canvas(id, { proxy: "https://html2canvas.appspot.com/query", onrendered: function(canvas) { var img = canvas.toDataURL("image/png"); var output = enpreURIComponent(img); var Parameters = "image=" + output + "&filedir=" + cur_path; $.ajax({ type: "POST", url: "inc/savePNG.php", data: Parameters, success : function(data) { console.log("screenshot done"); } }).done(function() { //$('body').html(data); }); } });}savePNG.php
<?php $image = $_POST['image']; $filedir = $_POST['filedir']; $name = time(); $image = str_replace('data:image/png;base64,', '', $image); $depred = base64_depre($image); file_put_contents($filedir . "/" . $name . ".png", $depred, LOCK_EX); echo $image;?>


