国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序學習筆記之文件上傳、下載操作圖文詳解

2024-07-22 01:18:53
字體:
來源:轉載
供稿:網友

本文實例講述了微信小程序學習筆記之文件上傳、下載操作。分享給大家供大家參考,具體如下:

前面介紹了微信小程序登錄API與獲取用戶信息操作。這里再來介紹一下文件的上傳與下載操作。

【文件上傳】wx.uploadFile

(以上傳圖片為例)

后臺上傳接口Upload.php:(tp5)

<?phpnamespace app/home/controller;use think/Controller;class Upload extends First{  //上傳圖片API  public function upImg() {  	$arr = array('state'=>0,'msg'=>'上傳失敗','filepath'=>'');    $file = request()->file('file');    if($file){      $info = $file->move('upload/weixin/');      if ($info) {        $arr['state'] = 1;        $arr['msg'] = '上傳成功';        $arr['filepath'] = $info->getSaveName();      }    }    return json($arr);  }}

前臺頁面upload.wxml:

<image src='{{imgpath}}' style='width:600rpx; height:600rpx' /><view> <button bindtap="upImg">點擊選擇上傳圖</button></view>

前臺upload.js:

Page({ data: {  imgpath: '' }, upImg: function (e) {  var that = this  wx.chooseImage({   count: 1, // 默認最多一次上傳9張圖片   sizeType: ['original', 'compressed'], // 允許原圖和壓縮圖   sourceType: ['album', 'camera'], // 允許相冊和相機   success(res) {    const tempFilePaths = res.tempFilePaths    wx.showToast({     title: '正在上傳...',     icon: 'loading',     mask: true,     duration: 500    })    wx.uploadFile({     url: 'https://www.msllws.top/Upload/upImg', //服務器上傳接口     filePath: tempFilePaths[0], //文件資源路徑     name: 'file',     header: {      'Content-Type': 'Application/json'     },     success(res) {      console.log(res)      if (res.statusCode == 200){       that.setData({        imgpath: tempFilePaths       })       }     }    })   }  }) }})

演示效果:

(其實是有正在上傳...效果的,手機錄屏沒給錄上。。)

 
查看服務器里面多了一張圖片:

嗯哼~

 【文件下載】wx.downloadFile

(以下載一張圖片為例)

在服務器目錄下放一張圖片1.jpg:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高邑县| 汉川市| 江华| 三江| 眉山市| 阿瓦提县| 南雄市| 潞城市| 来安县| 安阳县| 桓仁| 清河县| 隆尧县| 静乐县| 高要市| 台江县| 漯河市| 绥棱县| 竹北市| 高阳县| 白玉县| 黄浦区| 清丰县| 任丘市| 宜春市| 万年县| 邹平县| 剑河县| 上思县| 焦作市| 普洱| 巴里| 莫力| 阳曲县| 安远县| 高雄市| 鞍山市| 慈溪市| 洪泽县| 佳木斯市| 桂林市|