title: Download & Upload using Greasemonkey & PHP
body: <p>I need to transfer a file (.zip) from a clients third-party-website to mine.</p>
  
  <p><strong>GM-Snippet</strong> (commented out other trys)</p>
  
  <pre><code> GM_xmlhttpRequest({
      method: "GET",
      url: dlurl,
      timeout:0,
      onload: function(resp) {
      var conti=resp.responseText;
  
  alert("goup");
  GM_xmlhttpRequest({
      method: "POST",
      url: "http://absolut-fair.com/wbb_back/api.php?id=3",
      overrideMimeType: 'text/plain; charset=x-user-defined',
      data:"chk=1&amp;data="+base64_encode(conti),
      headers: {
              "Content-Type": "application/x-www-form-urlencoded"
      },
      onload: function(resp) {
          var conti=resp.responseText;
  
          if(conti=="1") alert("upload erfolgreich");
          else alert(conti);
  //....
  </code></pre>
  
  <p><strong>PHP-Snippet</strong></p>
  
  <pre><code>$name="test.txt";
  uploadfile(base64_decode($_POST["data"]),detect_mime($name),$name);
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>All of the decoded files are corrupted when I try to open them.
  The problem is sending binary data. Sending raw text worked fine!</p>
  
  <p><strong>//Update</strong></p>
  
  <p>I just downloaded the healthy and the invalid zip files and it appears that the invalid one handles a lot of space filling useless code segments.
  So i got the feeling that base64 is not able to fully encode/decode binary data. Anyone has any knowledge?</p>
  
  <p>I attached a screenshots of the source to make it clear!</p>
  
  <p><strong>The valid file:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/4PtP6.png" alt="the valid file"></p>
  
  <p><strong>The invalid one:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/iikAr.png" alt="the invalid one"></p>