收藏
回答

请问怎么在后台获取图片呢???求代码???

 //获取多张图片
  chooseImage: function () {
    var that = this;
    var res_url = app.globalData.res_url;
    wx.chooseImage({
      count: 4, // 最多可以选择的图片张数,默认9
      sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
      count: this.data.count[this.data.countIndex],
      success: function (res) {
        var tempFilePaths = res.tempFilePaths;
        // console.log(tempFilePaths)
        //console.log(res)
        // console.log('xxxxxx')
        that.setData({
          imageList: res.tempFilePaths,
        })
        wx.uploadFile({
          url: res_url + 'index.php?g=admin&m=wxxcx&a=release',
          method: "POST",
          header: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
            'user': 'test'
          },
          success: function (res) {
            var data = tempFilePaths[0]
            // console.log(data)
            that.setData({
              data: tempFilePaths[0],
            })
            //do something
          }
        }),
       
      }
    })
  },


这是我的代码??不知道怎么在后台获取图片??求解

回答关注问题邀请回答
收藏

7 个回答

  • Andy
    Andy
    2017-07-27

    参见  http://www.w3school.com.cn/php/php_file_upload.asp



    wx.uploadFile({
              url: res_url + 'index.php?g=admin&m=wxxcx&a=release',
              method: "POST",
              header: {
                "Content-Type": "application/x-www-form-urlencoded",
              },
              filePath: tempFilePaths[0],
              name: 'file',
              formData: {
                'user': 'test'
              },
              success: function (res) {
              //res 是服务器返回给你的数据
               console.log(res)
               
              }
            })

    2017-07-27
    有用
    回复
  • .
    .
    2017-07-27

    我是这么获取的,可是  echo $_FILE['file']   小程序调试界面里没有出来的说

    2017-07-27
    有用
    回复
  • Andy
    Andy
    2017-07-27

    $_FILES["file"] php里用这个获取上传上来的文件

    2017-07-27
    有用
    回复
  • .
    .
    2017-07-27

    wxfile://tmp_1083210676o6zAJs2v9SL4JvrbUfu1-h6QjeUs0a03b64871e0a85386ff85965c7c30d5.jpg

    可以出来,就是后台不知道怎么获取

    2017-07-27
    有用
    回复
  • .
    .
    2017-07-27

    就是不知道怎么在后台获取,

    2017-07-27
    有用
    回复
  • .
    .
    2017-07-27

    在data里,我打印了一下,可以出来路径的说

    2017-07-27
    有用
    回复
  • Andy
    Andy
    2017-07-27

    看你设定的值都是本地的 ,

    在wx.uploadFile 的success回调数据里面 给你远程图片路径了么? 有给你 就能拿到了

    2017-07-27
    有用
    回复
登录 后发表内容