title: Posting variable from js to php, strange encode64 situation in php?
body: <p>I have 2 files screen.js and test.php.
  I have this simple php code in test.php:</p>
  
  <pre><code>&lt;?php
  if (isset($_POST['img'])) {
  $img = $_POST['img'];
  $comma = strpos($img, ',');
  $data = substr($img, $comma+1);
  file_put_contents('MyFile.jpg', base64_decode($data));
  }
  ?&gt;
  </code></pre>
  
  <p>I have 2 situations:</p>
  
  <ol>
  <li><p>When I send via ajax img variable which contains jpg file, as string base64 from screen.js to test.php the script save a file on server side but I can't open it. I got error while opening!! :(</p></li>
  <li><p>While i debug the screen.js I know what img variable contains. When I copy and paste the contents of the img variable and save into test.php as below everyting is ok.</p>
  
  <p>if (isset($_POST['img'])) {
  $data2 = '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMC...etc.';
  file_put_contents('MyFile.jpg', base64_decode($data2));
  }</p></li>
  </ol>
  
  <p>So what's wrong?</p>