问题
ı 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