Ajax Simple File Upload

Ajax Simple File Upload

I'm actually new on jquery ajax. i just wanna ask a little idea about how to create simple file upload (with form) using ajax. i tried using this code:

//form html
  1. <p id="status"></p>
  2. <form id="form1" enctype="multipart/formdata">
  3. <input type="file" id="photo" name="photo" />
  4. <input type="submit" id="save" name="save" value="Upload" />
  5. </form>


//php file

  1. if($_POST){
  2. $name = $_POST['photo']['name'];
  3. $tmp = $_POST['photo']['tmp_name'];
  4. $path = "images/".basename(name);
  5. if(move_uploaded_file($tmp,$path)){
  6.         print("Done! File saved...");
  7. }else{
  8.         die("Error on uploading!")
  9. }
  10. }


//js

  1. $(document).ready(function(){
  2.      var photo = $("#photo").val();
  3.     $.post("upload.php",{photo:photo},function(data){
  4.       $("#status").html(data);
  5.      });
  6. });


i am totally confused on this. please help! thanks in advance!

~aleks