title: Handling plupload file uploads in Symfony 2
body: <p>I'm trying to write a controller to accept file uploads from the <a href="http://www.plupload.com/" rel="nofollow">Plupload</a> plugin. As an added bit of fun, the uploads are coming from a different URL so I have to set the <code>Access-Control-Allow-Origin</code> header myself. So far I've done that like so:</p>
  
  <pre><code>/**
   * @Route("/frontEnd/file/upload.{_format}")
   */
  public function upload(Request $request) {
      $response = new Response();
      $response-&gt;setContent(json_encode(array('hello' =&gt; 'world')));
      $response-&gt;setStatusCode(200);
      $response-&gt;headers-&gt;set('Access-Control-Allow-Origin', '*');
      $response-&gt;send();
  }
  </code></pre>
  
  <p>which seems to work. When I submit the uploads using plupload I see the XHR requests hit Symfony and the JSON is returned. However, I have no idea how to handle the actual file and move it into a directory.</p>
  
  <p>I did a <code>var_dump()</code> on <code>$_POST</code> and it only returned the following:</p>
  
  <pre><code>array(1) {
    ["name"]=&gt;
    string(21) "wallpaper-2873928.jpg"
  }
  </code></pre>
  
  <p>The upload is definitely being sent as I can see the file's bytes being part of the request payload with developer tools. Do I need to use Symfony's own components to handle the upload? If so, how? The Symfony documentation only seems to cover uploading from a file upload form.</p>