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.

1

1 Answer 1

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);
    }   
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.