title: Javascript array to file on server
body: <p>I have a JavaScript client which needs to send data to the server which will then save it as a file.
  The client doesn't allow websockets so I've tried using JSON to post it then save it using PHP on the server but as the data on the JavaScript client is a Uint32Array PHP doesn't understand what it is. </p>
  
  <p>This is what I have on the client side</p>
  
  <pre><code>var arrayData = new Uint32Array(256);
  ...
  var formdata = new FormData();
  formdata.append("data" , JSON.stringify(arrayData));
  var xhr = new XMLHttpRequest();
  xhr.open( 'post', 'receive.php', true );
  xhr.send(formdata);
  </code></pre>
  
  <p>Then on the server</p>
  
  <pre><code>&lt;?php
  if(!empty($_POST['data'])){
      $data = json_decode($_POST['data']);
      $fname = mktime() . ".txt";//generates random name
  
      file_put_contents("upload/" .$fname, data);
  }
  ?&gt; 
  </code></pre>
  
  <p>All I get in the text file is 'data' and a PHP error in the logs 
  'Use of undefined constant data - assumed 'data'</p>
  
  <p>I've no idea how to get PHP to write this as binary data so any help would be greatly appreciated! </p>