开发者

How to save a html5 Canvas.toDataURl string as a png on a php backend

开发者 https://www.devze.com 2023-03-05 03:43 出处:网络
After converting my canvas to a an image source using canvas.toDataURL(\"image/png\"); and p开发者_如何转开发assing it to a php file, how do I save it as a .png image on the server?It\'s actually

After converting my canvas to a an image source using

 canvas.toDataURL("image/png");

and p开发者_如何转开发assing it to a php file, how do I save it as a .png image on the server?


It's actually very simple, if you have allow-url-fopen enabled. PHP supports the data: URL scheme then, and automatically decodes base64 and urlencoding.

preg_match('#^data:[\w/]+(;[\w=]+)*,[\w+/=%]+$#', $data=$_POST["dataU"])
and
copy($data, "output.png");

But you could also just extract the part after the , and manually base64_decode() it.

0

精彩评论

暂无评论...
验证码 换一张
取 消