微信小程序wx.uploadFile(上传文件)PHP服务器获取formData的数据

微信小程序wx.uploadFile(上传文件)PHP服务器获取formData的数据_第1张图片

例如下面的代码是微信小程序上传图片的伪代码

wx.chooseImage({
  success: function(res) {
    var tempFilePaths = res.tempFilePaths
    wx.uploadFile({
      url: 'https://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
      filePath: tempFilePaths[0],
      name: 'file',
      formData:{
        'user': 'test',
        'new_file_name': '新名字'
      },
      success: function(res){
        var data = res.data
        //do something
      }
    })
  }
})

formData参数是HTTP 请求中其他额外的 form data。但是后台php服务器怎么获取里面数据。

可以简单的使用POST获取到,例如:

$_POST[“user”]获取到的就是test
$_POST[“new_file_name”]获取到的就是新名字


你可能感兴趣的:(php)