preface

almost every program needs to use pictures. Now let me introduce the front end +PHP back-end, WeChat small program to upload pictures, and share it for your reference. Let's have a detailed introduction below. The following

, a

method: wxml file

 < text> /text> < aion < view> button; < bindtap= uploadimg > click choose to upload maps < /button> < /view> < image src='{{source}}'style='width:600rpx; height:600rpx' /> 

two, JS

 Page file (* * / / * * {data: {/ / initial data page is initialized to the empty source:''} / * * * * uploadimg:function upload pictures () {var that = this; wx.chooseImage ({/ / from the local picture album or camera using count: 1, 9 sizeType: ['original''compressed'] / / default. You can specify, / / is the original or the default compression map, the two have sourceType: ['album','camera'], you can specify the source / / the album or camera, the default two have success:function (RES) {//console.log (RES) / that.setData (front display {source: res.tempFilePaths}) / / local file path to return a list of selected photos, tempFilePath can be used as SRC's img attribute var res.tempFilePaths wx.uploadFile display pictures tempFilePaths = ({url:'http://www.website.com/home/api/uploadimg', filePath: tempFilePaths[0], name:'file', success:function (RES) console.log (res.data) {/ / print}})}})}),}

, PHP

 three back-end code / / function (uploadimg) public upload pictures {$file = request (->); file ('file'); if ($file) {$info = $file-> Move; ('public/upload/weixin/'); if ($info) {$file = $info-> (getSaveName); $res = ['errCode'=> 0,'errMsg'=>' upload success','file'=> $file]; return JSON ($res);}}}

results:

style = "

at 2018010103036? "Said the success!

all above is the summary of this article, I hope this paper has some reference value of learning to learn or work, if in doubt, you can exchange messages, thank you for the support of the script.


This concludes the body part