Get the App
SLTechnology News&Howtos  ›  Development  › 

How to upload multiple pictures in H5

Shulou Source: shulou.com Published: 2022-06-03 12:16:35 11月15日 Update

This article will explain in detail how to upload multiple pictures on H5. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

This article mainly introduces the function of uploading multiple pictures based on HTML5 and the function of uploading multiple pictures on the basis of uploading a single picture. Interested friends can refer to it.

The picture was also written before uploading, but it was uploaded by a single sheet. Recently, there is a business requirement that requires multiple uploads, so I rewrote it.

HTML structure:

Please select an image file:

By the way, the main logic of this upload:

Use the input tag and select type=file, and remember to bring multiple, otherwise you will have to select the picture

Bind the change time of input

The key point is how to deal with this change event, use H5's new FileReader interface to read the file and encode it into base64, and then interact with the back-end students.

JS Code:

_ window.onload = function () {var input = document.getElementById ("file_input"); var result,p; if (typeof FileReader==='undefined') {result [XSS _ clean] = "Sorry, your browser does not support FileReader"; input.setAttribute ('disabled','disabled');} else {input.addEventListener (' change',readFile,false) }

/ / handler function readFile () {for (var iTuno

Tags: Pictures files front end multiple that is articles selections practices functions classmates interfaces data more formats structures codes paths pages references good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Huawei MySQL Shulou Information