通过ajax异步上传文件
解决方法:
var this_ = $("#file");
var size = (this_[0].files[0].size / 1024).toFixed(2);
var img = this_[0].files[0];
var formData = new FormData();
formData.append("imgFile",img);//imgFile是后台接收的参数名
$.ajax({
type:"post",
url:"/php/upload_json.php",
data:formData,
cache: false,
processData : false,
contentType : false,
beforeSend: function(XMLHttpRequest){
},
success:function(data){
},
error:function(data){
}
});
php后台接受参数:
$file_name = $_FILES['imgFile']['name'];
$file_size = $_FILES['imgFile']['size'];