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
- <p id="status"></p>
- <form id="form1" enctype="multipart/formdata">
- <input type="file" id="photo" name="photo" />
- <input type="submit" id="save" name="save" value="Upload" />
- </form>
//php file
- if($_POST){
- $name = $_POST['photo']['name'];
- $tmp = $_POST['photo']['tmp_name'];
- $path = "images/".basename(name);
- if(move_uploaded_file($tmp,$path)){
- print("Done! File saved...");
- }else{
- die("Error on uploading!")
- }
- }
//js
- $(document).ready(function(){
- var photo = $("#photo").val();
- $.post("upload.php",{photo:photo},function(data){
- $("#status").html(data);
- });
- });
i am totally confused on this. please help! thanks in advance!
~aleks