$.fn.up = function(callback) {
$(this).click(function() {
var fileInput = document.createElement('input');
fileInput.type = 'file';
$(fileInput).change(function() {
var file = this.files[0];
var formData = new FormData();
formData.append('file', file);
$.ajax({
url: '/api/common/upload',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(response) {
callback(response);
},
error: function(xhr, status, error) {
console.log(error);
}
});
});
fileInput.click();
});
};
//$("#filePicker1").up(function(response) {
// console.log(response);
//});
//上传后更新数据
// $("#upavatar").up(function(res) {
// if(res.code==1){
// $.post("/index/user/pic",{avatar:res.data.url}, function(response) {
// msg(response.msg);
// $(".xinziliao_txwx_img1").attr("src",res.data.url);
// });
// }else{
// msg(res.msg);
// }
// });
// $("#upwxcode").up(function(res) {
// if(res.code==1){
// $.post("/index/user/pic",{wxcode:res.data.url}, function(response) {
// msg(response.msg);
// $(".xinziliao_txwx_img2").attr("src",res.data.url);
// });
// }else{
// msg(res.msg);
// }
// });
//php
// public function pic(){
// $user = $this->auth->getUser();
// $wxcode = $this->request->post('wxcode');
// $avatar = $this->request->post('avatar');
// if($awxcode){
// $user->wxcode=$wxcode;
// }
// if($avatar){
// $user->avatar=$avatar;
// }
// $user->save();
// $this->success("更新成功!");
// }
发表评论 取消回复