简体   繁体   English

仅使用Javascript将画布图像保存到服务器

[英]Saving a canvas image to server using only Javascript

I know the way to do this with PHP but does anyone know a way of doing it only with JS & HTML? 我知道用PHP做到这一点的方法,但是没有人知道仅用JS和HTML做到这一点的方法吗?

The canvas image should be saved to a server, not locally. 画布图像应保存到服务器,而不是本地。

For JS in the browser security context, is not allowed to write to the user's file system Or to the server file system. 对于浏览器安全上下文中的JS,不允许写入用户的文件系统或服务器文件系统。

You must have a server side service that will intercept the file and than save it to the system. 您必须具有服务器端服务,该服务将拦截文件并将其保存到系统。

to achieve it using JS only, you need to use node.js as server side 要仅使用JS来实现它,您需要使用node.js作为服务器端

Try this: 尝试这个:

var canvas=document.getElementById("mycanvas");
var data=canvas.toDataURL("image/png");

Send the data to php in an ajax call 通过ajax调用将数据发送到php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM