title: upload file and some data with json
body: <p>I'm trying to upload a file to the sever. And also some comments from a input form about this data. </p>
  
  <p>Here I sent the data in js:</p>
  
  <pre><code>var postContainer = new Array();
          postContainer.push(
          {
              file : file,
              f_name : file.name,
              input1 : it1Value 
          });
  
          var newJ = JSON.stringify(postContainer);            
          xhr.setRequestHeader("X-File-Name", file.name);
          var resText;
          xhr.setRequestHeader("Content-type","application/json");
          xhr.onreadystatechange = function(){
              if(xhr.readyState != 4){
                  return;
              }
              console.log(xhr.responseText);
          }
          xhr.send(newJ);  
  </code></pre>
  
  <p>Then I read the data and send the file to the upload folder:</p>
  
  <pre><code>    $data = file_get_contents("php://input");
      $data = json_decode($data);
      var_dump($data);
      $this-&gt;fileName = $data[0]-&gt;{"f_name"};
      $this-&gt;genre = $data[0]-&gt;{"input1"};
      $this-&gt;file = $data[0]-&gt;{"file"};
              file_put_contents(
      $this-&gt;path . $this-&gt;fileName,
      $this-&gt;file
      );
  </code></pre>
  
  <p>The output in console of var_damp($data) is:</p>
  
  <pre><code>array
  0 =&gt; 
  object(stdClass)[2]
    public 'file' =&gt; 
      object(stdClass)[3]
        public 'webkitRelativePath' =&gt; string '' (length=0)
        public 'lastModifiedDate' =&gt; string '2012-06-26T06:25:34.000Z' (length=24)
        public 'name' =&gt; string 'Belgium.png' (length=11)
        public 'type' =&gt; string 'image/png' (length=9)
        public 'size' =&gt; int 28228
    public 'f_name' =&gt; string 'Belgium.png' (length=11)
    public 'input1' =&gt; string 'Genre' (length=5)
  </code></pre>
  
  <p>You can see the data is sent to the php page. But when I check my upload folder. I can find the file I upload. But the size is zero. That means I upload an empty file!!!</p>
  
  <p>Can some one help me to solve this problem? 
  Thank you very much!!</p>