我最近自己必须这样做.
首先,我将canvasData放入隐藏字段并将其发布到我的PHP页面.
它以这种格式返回:data:image / png; base64,iVBORw0 ……
您需要首先拆分数据,因为:data:image / png; base64,是标题信息.其余的是编码数据.
$rawData = $_POST['imageData'];
$filteredData = explode(',', $rawData);
$unencoded = base64_decode($filteredData[1]);
然后我在我的服务器上创建图像:
//Create the image
$fp = fopen('sigs/test1.png', 'w');
fwrite($fp, $unencoded);
fclose($fp);
然后阅读它以做任何我想要的事情.
$file_name = 'test1.png';
$file_size = strlen($filteredData[1])/1024; //This may be wrong, doesn't seem to break for me though.
$fh = fopen('sigs/test1.png', 'r');
$content = fread($fh, $file_size);
$content = base64_encode($content);
fclose($fh);
我更确定有一个更优雅的解决方案,但这对我有用!
查看此信息以获取更多信息(可能):My own question