小程序(php转base64)显示图片

php代码

        if($fp = fopen($path,"rb", 0))
        {
            $gambar = fread($fp,filesize($path));
            fclose($fp);
            $base64 = chunk_split(base64_encode($gambar));
            // 输出
            $encode =  $base64 ;
        }
        echo json_encode($encode); die;

小程序js

                        a.util.request({
                            url: "entry/wxapp/img",
                            method: "get",
                            dataType: "json",
                            data: {
                                username: '洋洋',
                                type: 1,
                                id:7
                            },
                            success: function(s) {
                                console.log(s);
                                var array = wx.base64ToArrayBuffer(s.data);
                                var base64 = wx.arrayBufferToBase64(array);
                                a.globalData.xiao_path = 'data:image/jpeg;base64,' + base64; // data 为接口返回的base64字符串
                            }
                        })

你可能感兴趣的:(微信小程序)