title: How save image from canvas tag to php server?
body: <p>I have a javascript code like this</p>
  
  <pre><code>var testCanvas = document.getElementById('canvas-1');
  var canvasData = testCanvas.toDataURL("image/png");
  var ajax = new XMLHttpRequest();
  ajax.open("POST",'http://www.domain.com/imgsave.php',true);
  ajax.setRequestHeader('Content-Type', 'canvas/upload');
  ajax.send("canvasData"+canvasData );
  </code></pre>
  
  <p>My php code is like this</p>
  
  <pre><code>if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
  {
      // Get the data
      $imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
  
      $filteredData=substr($imageData, strpos($imageData, ",")+1);
  
      $unencodedData=base64_decode($filteredData);
      $fp = fopen( 'test.png', 'wb' );
      fwrite( $fp, $unencodedData);
      fclose( $fp );
          echo "saved";
  }
    else{
  
    echo "no raw data";
    }
  </code></pre>
  
  <p>When executing this code i got a zero size png file image? Whats the problem with my code?</p>