title: How to get input type 'file' variable on JQuery page and then pass variable and file to PHP page for upload
body: <p>Image upload functionality is working fine using HTML, Javascript and PHP. But now I am trying to convert it into HTML, JQuery and PHP but I am not able to upload photo using below code. </p>
  
  <p>I am not able to get file type variable on .js page and then file itself on php page (upload_p.php)</p>
  
  <p>Please advise what I am doing wrong. I am trying to get this work for last 2 days but no luck yet.</p>
  
  <p><strong>upload.php</strong></p>
  
  <pre><code>&lt;form name="Uform" id="Uform" novalidate&gt;
  &lt;div class="control-group form-group"&gt;
      &lt;input type="file" name="img" id="img"&gt;
      &lt;div id="success"&gt;&lt;/div&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;Upload&lt;/button&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>upload.js</strong></p>
  
  <pre><code>$(function() {
  
  $("#UForm file").jqBootstrapValidation({
      preventSubmit: true,
      submitSuccess: function($form, event) {
          event.preventDefault(); 
  
          // Try #1
          var form   = new FormData() ;
          var file = $('#img')[0].files[0];
          formData.append("file", file);
  
          // Try #2
          var FileData = $('#img').prop('files')[0];   
          var form_data = new FormData();                  
          form_data.append('file', FileData);
  
  
          $.ajax({
              url: "./user/upload_.php",
              type: "POST",
              data: {
  
                  // Try #1
                  upload : 1,
                  data : file
  
                  // Try #2
                  img: img,
              },
              cache: false,
          })
      },
  });
  </code></pre>
  
  <p><strong>upload_p.php</strong></p>
  
  <pre><code>$str_photo = "";
  if(isset($_FILES['img'])) { $str_photo = trim($_FILES['img']['name']); }
  .
  .    
  UploadFile($_FILES["img"]["tmp_name"],$str_img_path);
  .
  .
  SQL Query to insert data into database table
  .
  .
  $response['status']='SUC';
  $response['message']="Image uploaded successfully";
  echo json_encode($response);
  return;
  </code></pre>