title: jQuery File Upload Using PHP
body: <p>I am trying to do a simple  pdf/excel file upload by storing the file into an upload folder and saving the name into the database. The problem here is that after i click on the upload button, the database saves my <code> $transaction-&gt;test = &quot;something&quot;;</code> but not the file or directory.</p>
  <pre><code>&lt;input type=&quot;file&quot; id=&quot;upload&quot; name=&quot;upload&quot; accept=&quot;application/pdf,application/vnd.ms-excel&quot; /&gt;
  &lt;input id=&quot;next&quot; class=&quot;btn btn-primary&quot; type=&quot;button&quot; value=&quot;Upload&quot; /&gt;
  
  &lt;script&gt;
  uploadFile : function (upload) {
             $.ajax({
                  type: 'POST',
                  url: 'upload.php',
                  data: { 
                  upload: $('#upload').val(),
                  },
                 success: function(data)
                  {
                      if(data.result == true){
                          alert(&quot;File has been uploaded successfully&quot;);
                      }   
                      else{
                      alert(&quot;Fail to upload file&quot;);
                      }       
                  },
              });
                  return false;
  }
  &lt;/script&gt;
  </code></pre>
  <h1>upload.php</h1>
  <pre><code>public function uploadFile($params){
      extract($params);
      $response = $this-&gt;response;
      $agentId = $this-&gt;getCurrentId();
      
      $agent    = Investor::fetch($agentId); //fetching user info
      if(count($POST)&gt;0){
          $d=(object)$POST;
          $transaction = new Transaction (); //create new data
          $transaction-&gt;test = &quot;something&quot;; //this works
          $target_dir = &quot;../uploads/&quot;;
          $target_file = $target_dir . basename($_FILES[&quot;upload&quot;][&quot;name&quot;]);
          $fileUpload = move_uploaded_file($_FILES['upload']['tmp_name'], $target_file);       
           if($fileUpload){
               $transaction -&gt;description = $fileUpload;
               $transaction-&gt;save ();
               $this-&gt;success();
               $this-&gt;response['result'] = true;       
           }
           else{
              $this-&gt;response['result'] = false;
           }
          }
      return $this-&gt;response;
   }
  </code></pre>