$.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("更新成功!");

    // }

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部