title: Upload img without using submit button or rederict in PHP & AJAX
body: <p>This might look like a duplicate but I have not found something that matches my needs exactly yet. I want to upload an Image to a folder by just choosing a file in the file browser, no submit button used (so far so good, i can do this). But then I want the user not be redirected the to <code>upload.php</code> file.
  So I need to submit a file without a using submit button and not redirecting the user to another page. A refresh is ok but preferable without refresh as well.. 
  This is what i have right now, and my question is if this could be done in <code>PHP,AJAX &amp; Javascript</code> or if i should go for a <code>JQuery plugin</code>?</p>
  
  <p>AND I will have several forms so i am not using ID-tag</p>
  
  <p>My code so far doesn't work 100%, only when i upload and redirect to <code>upload.php</code> :</p>
  
  <pre><code>&lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
    &lt;input type="file" name="fileToUpload" class="test"&gt;
  &lt;/form&gt;
  
      $(".test").change(function() { 
          $.ajax({
              url: "upload.php",
              type: "post",
              dataType: 'json',
              processData: false,
              contentType: false,
              data('file', $(this[0].files[0])),
              success: function(text) {
                      alert("successfully");
              }
          });   
      });
  </code></pre>
  
  <p><strong>UPLOAD.PHP</strong></p>
  
  <pre><code>&lt;?php if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "uploads/myfile.jpg")) {
      echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
   } else {
      echo "Sorry, there was an error uploading your file.";
       }
   }?&gt;
  </code></pre>