title: Edit existing jQuery function to add upload file
body: <p>I have some working code but want to add upload image field but with no success.
  My current code is:</p>
  
  <p>Form:</p>
  
  <pre><code>&lt;form id="add_product_form" enctype="multipart/form-data"&gt;
      &lt;input id="uploadFile" type="file" name="image" class="img" /&gt;&lt;br /&gt;
      &lt;input id="status" type="checkbox" checked /&gt;&lt;br /&gt;
      &lt;input id="product" type="text" /&gt;&lt;br /&gt;
      &lt;label for="button" id="response"&gt;&lt;/label&gt;
      &lt;input type="button" id="button" value="Добави" /&gt;&lt;br /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $('document').ready(function(){
      $('#button').click(function(){
  
          var image = $('input[type=file]').val().split('\\').pop();
          function chkb(bool){ if(bool) return 1; return 0; } var status=chkb($("#status").is(':checked'));
          if($('#product').val()==""){ alert("enter name"); return false; } else { var product = $('#product').val(); } 
  
          jQuery.post("products_add_process.php", { 
              image: image,
              status: status, 
              product: product
              }, 
  
          function(data, textStatus) {
              $('#response').html(data);
              if(data == 1){
                  $('#response').html("OK");
                  $('#response').css('color','green');
                  document.getElementById("add_product_form").reset();
              } else {
                  $('#response').html("Not OK");
                  $('#response').css('color','red');
              }
          });
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>products_add_process.php:</p>
  
  <pre><code>&lt;?php
  $image_name = $_FILES['image']['name'];
  $image_type = $_FILES['image']['type'];
  $image_size = $_FILES['image']['size'];
  $image_tmp_name = $_FILES['image']['tmp_name'];
  $status = $_POST['status'];
  $product = $_POST['product'];
  
  if($image_name == '') {
      echo "&lt;script&gt;alert('Select image')&lt;/script&gt;";
      exit();
      } else {
          $random_digit=rand(0000000000,9999999999);
          $image=$random_digit.$image_name;
          move_uploaded_file($image_tmp_name,"uploads/$image");
  
          $query=mysql_query("INSERT INTO products(product, image, status) VALUES ('$product', '$image', '$status')");
  
          if(mysql_affected_rows()&gt;0){
              $response = 1;
              echo "1";
              } else {
              $response = 2;
              echo "2";
              }
          }
  ?&gt;
  </code></pre>
  
  <p>I put alert 'Select image' and then understand that <code>$image_name</code> is empty and maybe somewhere have to put some code to say that I want to send DATA TYPE. I try to add to form <code>enctype="multipart/form-data"</code> but won't work.</p>
  
  <p>Where and what have to add in existing code to make sending data, without making very big changes because this code have in a lot of files and will be difficult to edit big part of codes.</p>
  
  <p>Maybe have to add that form and jQuery are in php file which is called in other mother file and structure is something like this:</p>
  
  <pre><code>products.php /call products_add.php/
     products_add.php /where is the form and jQuery/
         products_add_process.php /called from products_add.php to upload data/
  </code></pre>
  
  <p>p.s. Sorry if I don't explain my problem well but I'm from soon at stackoverflow and still learning how to post my questions :) </p>