title: Issue uploading a file via ajax using PHP
body: <p><em>Before starting, note that I have to update a website that is not mine, so I can't redo the whole logic. If I were to do this I would do it differently.</em></p>
  
  <p>I have a cakephp application with a form with a lot of fields. In this form you can browse for a file and save it asynchronously. Here is how it's done:</p>
  
  <pre><code>&lt;input type="file" name="data[FileUpload][file]" id="myFileToUpload"&gt;
  &lt;a id="pickFile" href="#"&gt;Upload&amp;nbsp;Now&lt;/a&gt;
  
  &lt;script type="text/javascript"&gt;
      $('#pickFile').click(function (e) {
          e.preventDefault();
          $.post(
              "/admin/FileUploads/saveFromFlash/&lt;?php e($session-&gt;id()) ?&gt;", {
              data: $("#myFileToUpload").val()
          }, function (data) {
              $("#returnedContentFromAjax").html(JSON.stringify(data));
          },
              "json");
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>The function called mainly does this:</p>
  
  <pre><code>$this-&gt;FileUpload-&gt;save($this-&gt;data)
  </code></pre>
  
  <p>but this always returns false and "No upload passed". Here is the line creating the error message:</p>
  
  <pre><code>if (!isset($this-&gt;data['FileUpload']['file'])) {
          $this-&gt;setUploadError('No upload passed');
      return false;
  }
  </code></pre>
  
  <p>I have no clue how to send this "$this->data['FileUpload']['file']" via ajax...  I guess this is the key problem since I don't know what object to pass here:</p>
  
  <pre><code>{ data:$("#myFileToUpload").val() },
  </code></pre>
  
  <p>I've been on it all evening, any help would be greatly appreciated</p>