title: Retrieving form data from JSON using PHP
body: <p>I am trying to pass some form data to a php page using JSON as shown below.</p>
  
  <pre><code> var file = doc.output('blob');
                  var fd = new FormData();     // To carry on your data  
                  fd.append('mypdf',file);
                  fd.append('x','&lt;?php echo $_GET['x']?&gt;');
                 // alert('file');
  
                  $.ajax({
                    url: 'week-distribute.php',   //here is also a problem, depends on your 
                    data: fd,           //backend language, it may looks like '/model/send.php'
                    dataType: 'text',
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    success: function (response) {
                      console.log('Success to send request');
                    },
                    error: function (jqXHR) {
                      console.log('Failure to send request');
                    }
                  });
  </code></pre>
  
  <p>The problem I have is that I cannot figure out how to retrive the data from the JSON object. I have tried the following (along with many other attempts) but this does not seem to work. Does anyone know how I can tried both the values x and mypdf please?</p>
  
  <pre><code>$json_data = file_get_contents("php://input");
  
  $data = json_decode($json_data, true);
  
  $x = $data["x"]; //This does not work
  
  $target_file = basename($_FILES["mypdf"]["name"]).uniqid().'.pdf'; //This does not work
  </code></pre>
  
  <p>This is how the form data is passed across in the headers:</p>
  
  <p>mypdf: (binary)
  x: eyJ0eXAiOiJKV1QiLCJh</p>