小程序图片上传tp5 php,微信小程序 tp5上传图片

test.wxml页面

请选择要反馈的问题view>

{{array[index]}}view>

image>

picker>

view>

图片添加view>

image>

删除button>

view>

image>

view>

提交 button>

test.js页面

var app = getApp();

Page({

data: {

array: ['程序错误', '软件改善', '业务建议'],

index:0,

msg:'',

button_status: 'default',

image:[],

img_button:'inline-block',

},

bindPickerChange: function (e) {

this.setData({

index: e.detail.value

});

},

Submit: function (e) {

if(this.data.msg.length != 0){

var that=this;

wx.showModal({

title: '提示',

content: '是否确认提交?',

success: function (res) {

if (res.confirm) {

wx.request({

url: app.appUrl.url + 'advise/uid/' + app.appData.userid + '/type/' + that.data.array[that.data.index] + '/content/' + that.data.msg,//+pic=图片地址1,图片地址2,图片地址3此处读取图片隐藏域的图片地址,多张用逗号分隔

header: {

"Content-Type": "applciation/json"

},

method: "POST",

success: function (res) { },

fail: function (err) { },

complete: function (res) {

wx.showToast({

title: '提交成功',

image: '/image/right.png',

duration: 3000

})

setTimeout(function () {

wx.clearStorage()

wx.navigateBack({

delta: 1

})

}, 2000);

},

})

}

},

})

}

},

feedbackInput: function (event) {

console.log(event.detail.value.length);

if (event.detail.value.length==0){

this.setData({

button_status: 'default',

});

}

else{

this.setData({

button_status: 'primary',

});

}

this.setData({

msg: event.detail.value,

});

},

uploadImg:function(){

var that = this, image = this.data.image;

if(this.data.image.length<3){

wx.chooseImage({

count: 1, // 默认9

sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有

sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有

success: function (res) {

wx.uploadFile({

url: app.appUrl.url + 'upload',//这个方法就是后台处理上传的方法

filePath: res.tempFilePaths[0], //获取到上传的图片

name: 'file',

success: function (info) {

console.log(info);//info.data就是上传成功的图片名称 您可以在wxml里面搞一个隐藏域存储起来,在上面Submit提交里拼装一块提交出去

}

})

},

complete: function (res) {

// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片

if (that.data.image.length==2){

that.setData({

img_button: 'none',

})

}

image.push(res.tempFilePaths);

that.setData({

image: image,

})

}

})

}

},

delectImg:function(e){

var image = this.data.image;

image.splice(e.currentTarget.dataset.num,1);

this.setData({

image: image,

img_button: 'inline-block',

})

},

})

thinkphp5接受处理

//图片上传

public function upload(){

$file = request()->file('file');

$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/images');

if($info){

echo $info->getSaveName();

die();

}else{

echo $file->getError();

die();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值