微信小程序-过滤不合法图片格式

    wx.chooseImage({
      count: num,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
         //临时图片文件
         let tempImg = res.tempFilePaths[0];
         let filetype = tempImg.substring(tempImg.lastIndexOf(".")+1);
         if(!("jpg" == filetype || "png" == filetype || "jpeg" == filetype || "gif" == filetype)){
           wx.showModal({
             title: '格式错误',
             content: '合法格式为(png,jpg,jpeg,gif)',
             showCancel:false
           })
         }else{
         //合法
           that.handleUploadSuccContent(e, mes, res)
         }
      }
    })
发布了74 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_38188047/article/details/103250801