php image upload with jquery post

萝らか妹 提交于 2019-12-12 20:14:05

问题


ı 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:


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);
    }   
});


来源:https://stackoverflow.com/questions/8991471/php-image-upload-with-jquery-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!