title: jQuery - FileUpload plugin - PHP UploadHandler
body: <p>I setup the jQuery FileUpload (basic version as seen here <a href="http://blueimp.github.io/jQuery-File-Upload/basic.html" rel="nofollow">http://blueimp.github.io/jQuery-File-Upload/basic.html</a>), and get my files uploaded into <code>server/php/files</code> directory just fine.</p>
  
  <p>For the regular <code>input type="file"</code> I used following code:</p>
  
  <pre><code>    // if there's an CV already and no file was submitted
      if ($_POST['cv_id'] &amp;&amp; !$_FILES['file']['tmp_name']) {
          // set current CV and job offer reply relationship
          $module_name = 'Documents';
          $link_field_name = 'hrjob_jobofferreplies_documents';
          $sugar-&gt;set_relationship($module_name, $_POST['cv_id'], $link_field_name, $job_offer_reply_id['id']);
  
      }
  
      // if a file was submitted and there's another CV already
      if ($_POST['cv_id'] &amp;&amp; $_FILES['file']['tmp_name']) {
          // set status of old CV to inactive
          $values = array(
              'id' =&gt; $_POST['cv_id'],
              'status_id' =&gt; 'Expired'
          );
          $sugar-&gt;set('Documents', $values);
  
      }
  
  
  // if CV was submitted
  if ($_FILES['file']['tmp_name']) {
          $handle = fopen($_FILES['file']['tmp_name'], "rb");
          $filename = $_FILES['file']['name'];
          $contents = fread($handle, filesize($_FILES['file']['tmp_name']));
          $binary = base64_encode($contents);
  
          // create document in SugarCRM
          $values = array(
               'filename' =&gt; $filename,
               "document_name" =&gt; "Job Offer Reply",
               'category_id' =&gt; 'Resume',
               'status_id' =&gt; 'Active'
          );
  
          $doc_id = $sugar-&gt;set('Documents',$values);
  
          // create revision no. 1 to actually upload the document
          $sugar-&gt;set_document_revision($doc_id['id'],1,$binary,$filename);
  
      }
  </code></pre>
  
  <p>This code resided inside a function in a custom Wordpress plugin. </p>
  
  <p>What is the correct way to make it work with jQuery FileUpload plugin? Should I call this code somehow, or should I use the UploadHandler class?</p>