title: saving canvas in php but no data in image file
body: <p>Following code i am trying to save canvas on my Machine . in folder image file is created but it is of 0kb .</p>
  
  <p>on click of download button i am setting value in text and on next php page i am reading value with <code>$_POST['img_name'];</code> .</p>
  
  <p>JQuery ::</p>
  
  <pre><code>$("#Download").click(function() {
      console.log('Download clicked');
      //alert('Download clicked');
      var myval = canvas.toDataURL();
      $('#img_txt').val(myval);
  });
  </code></pre>
  
  <p>php code ::</p>
  
  <pre><code>&lt;?php
  $myval = $_POST['img_name'];
  echo "string is ".$myval; 
  ?&gt;
  
  &lt;?php
  $data = base64_decode($_POST['img_name']);
  
  /* Name the file anything you want */
  $filename = 'my_image.png';
  
  /* Remove 1st line of base64 string */ 
  /* Note: replace '$base64' with your own variable */
  $img = str_replace('data:image/png;base64,', '', $data);
  
  
  /* Replace spaces */
  $img = str_replace(' ', '+', $img);
  
  /* Decode string */
  $data = base64_decode($img);
  
  /* Full path to upload directory with at the end the filename */
  $file = 'D:/upload/'.$filename;
  
  /* Save, make sure the directory is writeable! */
  file_put_contents($file, $data);
  ?&gt;
  </code></pre>
  
  <p>I have check $_POST['img_name'] i am getting base64 string ? what is the problem in my code?</p>