[英]Save Canvas image (Post the data string to PHP)
I'm looking to learn Javascript and have been wanting to for a while, I got a little tutorial on how to create a HTML5 Canvas drawing application, I'm trying to modify it so I can save the image to my MySQL database. 我正在寻找学习Javascript并且已经想了一段时间,我得到了一个关于如何创建HTML5 Canvas绘图应用程序的小教程,我正在尝试修改它以便我可以将图像保存到我的MySQL数据库中。 So far, the code below simply redirects to my PHP file and does have the code I'd like, but it's a little big so I was wondering if there was a way to reduce that or possibly even _POST it to the PHP script.
到目前为止,下面的代码只是重定向到我的PHP文件并且确实有我喜欢的代码,但它有点大,所以我想知道是否有办法减少甚至可能_POST它到PHP脚本。
saveAsPNG : function(oCanvas, bReturnImg, iWidth, iHeight) {
if (!bHasDataURL) {
return false;
}
var oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight);
var strData = oScaledCanvas.toDataURL("image/png");
window.location.href = "http://localhost/save_server/?image=" + strData;
if (bReturnImg) {
return makeImageObject(strData);
} else {
saveFile(strData.replace("image/png", strDownloadMime));
}
return true;
},
I'm using window.location.href to send the data. 我正在使用window.location.href来发送数据。 Any help would be appreciated.
任何帮助,将不胜感激。 The URL which it currently gives is...
它目前提供的URL是......
localhost/save_server/?image=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4EAAAIUCAYAAACkdimIAAAgAElEQVR4Xu3XQQEAAAgCMelf2iA3GzD8sHMECBAgQIAAAQIECB... You know what? localhost / save_server /?image = data:image / png; base64,iVBORw0KGgoAAAANSUhEUgAAA4EAAAIUCAYAAACkdimIAAAgAElEQVR4Xu3XQQEAAAgCMelf2iA3GzD8sHMECBAgQIAAAQIECB ...你知道吗? It is so big, I'm not even going to post it here.
它太大了,我甚至不打算在这里贴出来。
Thanks for any help in advance! 在此先感谢您的帮助!
Use form
, and send bytes by POST
method: 使用
form
,并通过POST
方法发送字节:
var form = document.createElement("form");
form.setAttribute("action","http://localhost/save_server/");
form.setAttribute("enctype","multipart/form-data");
form.setAttribute("method","POST");
form.setAttribute("target","_self");
form.innerHTML = '<input type="hidden" name="image" value="'+strData+'"/>';
form.submit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.