


Analysis of an example of limiting the size of multiple images uploaded by WeChat applet
Recently I am working on a WeChat applet project. The purpose is to upload multiple pictures. The number cannot exceed 3. Moreover, in PHP, because the picture upload is set to only upload 2M, the upload is unsuccessful, so I set it on the front end. A function that uses the WeChat API (wx.chooseImage) to obtain pictures. If the picture is larger than 3, a prompt will pop up and the picture cannot be uploaded. If the picture is larger than 2M, a prompt will pop up. Only pictures under 2M can be uploaded. ,
data:{ img:[], //设置一个数组 } add_img:function(){ var that = this, img = that.data.img; if(img.length < 3){ //如果图片数量小于3张,可以直接获取图片 wx.chooseImage({ count:1, //默认9 sizeType:['compressed'], //可以指定原图还是压缩图,默认二者都有 sourceType:['album','camera'],//可以指定来源相册还是相机,默认二者都有 success:function(res){ var tempFilesSize = res.tempFiles[0].size; //获取图片的大小,单位B if(tempFilesSize <= 2000000){ //图片小于或者等于2M时 可以执行获取图片 var tempFilePaths = res.tempFilePaths[0]; //获取图片 that.data.img.push(tempFilePaths); //添加到数组 that.setData({ img:that.data.img }) }else{ //图片大于2M,弹出一个提示框 wx.showToast({ title:'上传图片不能大于2M!', //标题 icon:'none' //图标 none不使用图标,详情看官方文档 }) } } }) }else{ //大于三张时直接弹出一个提示框 wx.showToast({ title:'上传图片不能大于3张!', icon:'none' }) } }
I use the size in tempFiles to determine the image size. The minimum version supported is 1.2.0 (I don’t understand, I know where this 1.2.0 is from) Version? WeChat version or WeChat applet development tool version? Comment if you know, thank you)
Related articles:
Example detailed explanation of WeChat applet uploading pictures to the server
Implementation example code of multiple image uploads in WeChat Mini Program
Related videos:
Comprehensive and in-depth analysis video tutorial of WeChat Mini Program
The above is the detailed content of Analysis of an example of limiting the size of multiple images uploaded by WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software