2

ı want to upload image with jquery post. ı dont want to use form.

the problem is ı just got image name, ı cant use this:

 $size=filesize($_FILES['image']['tmp_name']);

 $copied = copy($_FILES['image']['tmp_name'], $newname);

my jquery function:

$('#add').click(function(){

    var image=$('#image').val();


    $.post(
            'select.php?p=up',
            {img:image},
            function(answer){

                $('#sonuc').html(answer);
            }
    );

});

html code:

<form name="newad" method="post" enctype="multipart/form-data"  action="" id="form">
<table>
<tr><td><input type="file" name="image" id="image"></td></tr>
<tr><td><input name="Submit" type="button" value="Upload" id="add"></td></tr>
</table>    
</form>

not: it works when ı submit form but it doesnt work like this, and ı have to do this.

guybennet
  • 683
  • 1
  • 9
  • 25
  • This question has already been asked here: [http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery][1] [1]: http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery – Nir Alfasi Jan 24 '12 at 17:50

1 Answers1

1

I recommend using jsupload plugin for this purpose. Your javascript would be:

$(document).ready(function() {
$("#uploadbutton").jsupload({ 
    action: "addFile.do",
    onComplete: function(response){
      alert( "server response: " + response);
    }   
});