微信小程序之文件上传PHP后台接收

微信小程序之文件上传(word,excel图片等)

微信前台代码
.html



    
        
    

.js

// pages/demo4/demo4.js
Page({

 /**
  * 页面的初始数据
  */
 data: {

 },

 uploadImg:function(){

   var that = this;
   wx.chooseMessageFile({
    count: 10,
    type: 'file',
    success(res) {
     // var filename = res.tempFiles[0].name
     // console.info(filename);
     // that.setData({ filename: filename });

      console.log(res.tempFiles[0].path)
     wx.uploadFile({
      url: 'http://49.122.47.146/php-yuyin/upload.php', //仅为示例,非真实的接口地址
      filePath: res.tempFiles[0].path,
      name: 'file',
      success(res) {
       //json字符串 需用JSON.parse 转
      }
     })

    }
   });
  
 },


 /**
  * 生命周期函数--监听页面加载
  */
 onLoad: function (options) {

 },

 /**
  * 生命周期函数--监听页面初次渲染完成
  */
 onReady: function () {

 },

 /**
  * 生命周期函数--监听页面显示
  */
 onShow: function () {

 },

 /**
  * 生命周期函数--监听页面隐藏
  */
 onHide: function () {

 },

 /**
  * 生命周期函数--监听页面卸载
  */
 onUnload: function () {

 },

 /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
 onPullDownRefresh: function () {

 },

 /**
  * 页面上拉触底事件的处理函数
  */
 onReachBottom: function () {

 },

 /**
  * 用户点击右上角分享
  */
 onShareAppMessage: function () {

 }
})

php后台代码

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