[当我单击捕获按钮时,数据将被保存在服务器的上载文件夹中,而不是我希望将数据保存在桌面中。这样客户端可以截取表单的屏幕截图,并将数据保存在他们的PC中。但是我没有找到任何解决方案。我是这种编码语言的新手,所以无论我得到什么文件,这个文件都可以正常工作,但是它将数据保存在我要保存在客户端桌面的服务器文件夹中,以便它们可以保存在PC中。
<script>
function doCapture() {
window.scrollTo(0, 0);
html2canvas(document.getElementById("about_data")).then(function(canvas) {
console.log(canvas.toDataURL("image/jpeg", 0.7));
var ajax = new XMLHttpRequest();
ajax.open("POST", "save-capture.php", true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.send("image=" + canvas.toDataURL("image/jpeg", 0.9));
ajax.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
}
});
}
</script>
<?php
$image= $_POST["image"];
$image=explode(";",$image)[1];
$image = explode(",",$image)[1];
$image= str_replace(" ","+",$image);
$image=base64_decode(($image));
file_put_contents("uploads/filename.jpeg",$image);
?>
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS81RDZINC5wbmcifQ==” alt =“在此处输入图像描述”>
[当您使用php和ajax POSt请求时,基本上是将信息从浏览器传递到服务器... file_put_contents定义为服务器端文件保存命令
您的解决方案必须在Javascript方面,打开一个对话框供用户保存文件。不需要php或ajax
经过一番谷歌搜索后,我找到了一个可以做到这一点的库,需要使用jQuery
http://johnculviner.com/jquery-file-download-v1-4-0-released-with-promise-support/