PHP如何将Canvas Snapshot作为PNG从数据保存到服务器端,而不是base64

So I've been looking around and could only find a way to save the image to a server if the data you send is in base64. I am sending the data as regualar data so nothing I found worked.

Thanks

This is what I tried to use:

 <?php
  $data = 'data:image/png;base64,AAAFBfj42Pj4';

  list($type, $data) = explode(';', $data);
  list(, $data)      = explode(',', $data);
  $data = base64_decode($data);

  file_put_contents('/tmp/image.png', $data);
?>

I also tried this:

$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));

The optimal way to return a Canvas image to PHP is describe in the following post:

How to save a HTML5 Canvas as Image on a server

1) Draw something

2) Convert canvas image to URL format (base64)

3) Send it to your server via Ajax

3) Save base64 on your server as an image