How to save a html5 Canvas.toDataURl string as a png on a php backend
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.
精彩评论