PHP数据URI到图像文件错误 - Windows无法预览

I tried converting a data URI generated using

canvas.Canvas.toDataURL();

I am just trying to store the data URI as image using the following code

<?php $data = $_POST['image_designed'];
echo $data; //Data URI
echo '<img src="'.$data.'"/>'; //Getting the image perfectly
//removing the "data:image/png;base64," part
$uri =  substr($data,strpos($data,",")+1);

header('Content-type: image/png');
echo base64_decode($uri);exit; //Just image place holder displaying instead of full image

I am getting the following data

$data = data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAEsCAYAAADq/K67AAAgAElEQVR4Xky9WY8l6Xnn90acPffMqspauqqrit3sZrO5z2g0FATJIw0G8L0/gr
//Very longer data than this which cannot be pasted here

The final image result is wrong. Just displaying an error image placeholder. I guessed the reason is "I found long space in the middle of my $data". But it renders the image well in src tag.